0

Is there a method or do you know a possibility to find out the optimal text size in a text view? I think this could be very usefull if you have a changing text in a text view. This could also solve the Problem, that text on a small Screen is to big and the same text size is to small on a big Screen.

  • See http://stackoverflow.com/questions/5033012/auto-scale-textview-text-to-fit-within-bounds – ridoy Jun 30 '13 at 15:38

2 Answers2

0

Well you have dp & sp.

dp
Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".

sp
Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.

I would recommend 14sp, which is the default size.

If you would like to have bigger text on bigger devices. Create a layout-xhdpi (etc.) folder, copy your layout file, and take 20sp for example.

You should use styles, then you can have separate folders "values" (default) "values-hdpi" (high density) "values-mdpi" (medium density) and so on and put your style file with correct textSize values in each folder as needed.

Then, when you are in medium density device it will pick the file in "values-mdpi" folder if exists or in "values" if not, and the same for high density etc...

source: Different font sizes for different screen sizes

Community
  • 1
  • 1
Mdlc
  • 6,388
  • 11
  • 48
  • 95
  • thx but this does not solve the problem when the text changes. And I still think that 14sp is to small on 10" tablet... – Eurohardware Jun 30 '13 at 15:49
0

A very helpful tool in creating layouts that can fit all screen sizes is the attrs.xml. Like drawable-hdpi, drawable-mdpi, etc., you can customize the size of texts (and whatever attribute you want to customize for different screens) by creating a size-specific values folder.

Android also comes with built-in "recommended sizes". Try typing in

?android:attr/text

ctrl+space to see the list of recommended sizes for some of the most common elements that has text in it.

For TextViews you can also modify its style (not textStyle) and use some built-in values such as

@android:style/TextAppearance.Medium
josephus
  • 8,148
  • 1
  • 35
  • 53