Android: How to size buttons?
That is difficult to answer in the abstract. Here are some techniques to consider:
Use
android:padding="4dip"
(or some other value) to make awrap_content
Button
a bit biggerUse
android:textSize
on theButton
to make the content bigger (use some size in scaled pixels, orsp
)If you want the buttons to fill the space but divide it among themselves, use a
LinearLayout
, give each button a height (or width, depending if column or row) of0px
, then useandroid:layout_weight
to allocate space between them on a percentage basis. Here is a sample project outlining this technique.
forneo
Updated on July 18, 2022Comments
-
forneo almost 2 years
I'm using several buttons in my app, but both layout_width/height "wrap_content" and "fill_parent" looks weird. The former being to small and the latter too large - both looks weird, and the former is not easy to hit with your finger.
How should I size buttons? Is it typical to define their sizes in dip? Or should I use "fill_parent" with a padding? Buttons looks weird in my app, not so in others.
-
forneo over 13 yearsOK. I ended up using paddingLeft and paddingRight of 20dip and paddingTop and paddingBottom of 10dip. Looks good that way and should be flexible with both layout changes and translation.