tv.setTextSize(14);
I set TextView font size to 14sp.
When I run my app in Nexus One, font size is ok.
But, when I run it in Nexus 7, font size is so small.
This is because Android scales font size according to density.
Nexus 7 density is lower than Nexus One, Android scaled font size down.
How can I adjust font size proportional to screen size?
Use an XML resource. In an XML resource file (I usually call mine ‘dimens.xml’), define a dimension resource called something like
font_size. Create a ‘dimens.xml’ file in the folders ‘values-normal’ and ‘values-large’. The font size in ‘values’ will be used by default, but a large screen (like the Nexus 7) will use the size in ‘values-large’. You could also define it in ‘values-xlarge’ if you wanted to explicitly support 10″ tablets.Settings the size can be done in XML with
textSize="@dimen/font_size"and from code withtv.setTextSize(getResources().getDimension(R.dimen.font_size)).Your dimens.xml file should look like this: