Android button and text size

I have a layout with several buttons that occupy the space of the entire layout using weighted properties. Each button has some text on it with a fixed size set by android: textSize = "30dp", so the size of the text on the screen size of a small mobile device (phone) depends on the size of the button. But on a large device (tablet), the button size expands, but the text size remains the same (30dp).

I want the button size and text size to be supported in each resolution, can this be done using layout XML? I would like to do this programmatically.

+4
source share
2 answers

The solution is very simple.

You should use size.xml with different sizes of each density / size and place it:

  • MDPI Values
  • HDI Values
  • xhdpi values
  • large values ​​(5.1 '5.4' y nexus7 tablets / phones)
  • values-xlarge (larger tablets)

You can use values-sw600dp (nexus 7) and values-sw720dp (10 ') too.

Oh! And use sp for text, not dp. SP is the same size for all fonts. Allways text with SP

Remember that you can always create values ​​/ drawings / resources in general for many separate configurations: Landscape portrati, langauge, dimensions, density, night or day, android version .... And you can combine it!

http://developer.android.com/intl/es/guide/topics/resources/providing-resources.html#SmallestScreenWidthQualifier

+7
source

text size should be specified in sp , not in dp, try as

  android:textSize="30sp" 

The size of the text. Recommended dimension type for text is "sp" for scaled-pixels .

+1
source

Source: https://habr.com/ru/post/1436776/


All Articles