I have a layout with a few buttons that takes the space of the entire layout using weight properties. Each button has some text on it with a fixed size which is set by android:textSize="30dp" so on a screen size of a small mobile device (A phone) the text's size if about the size of the button. But on a large device (A tablet) the button size expands yet the text size remains the same (30dp).
I want the button size and text size ratio to be maintained in every resolution, can it be done using the layout XML code? I would like to avoid doing it programmatically.
The solution is very simple
You should use a dimension.xml with diferent sizes each density/size and place it on:
You can use values-sw600dp (nexus 7) and values-sw720dp(10') too.
Ah! And use sp for text, not dp. SP put the same size for all the fonts. Text Allways with SP
Remember, you allways can create values/drawables/resources in general for a lot of separate configurations: Landscape portrati, langauge, sizes, densities, night or day, version of android .... And you can merge it!
http://developer.android.com/intl/es/guide/topics/resources/providing-resources.html#SmallestScreenWidthQualifier
text size should be mentioned in sp
, not in dp try like this
android:textSize="30sp"
Size of the text. Recommended dimension type for text is "sp"
for scaled-pixels
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With