Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView FontSize according to Different Resolution and ScreenSize

Here i develop one Android application, which can run on all screen size and resolution devices. But one problem is there my TextView's Fontsize is same on all the Screen-Size. I want to change FontSize according to Different ScreenSize and Screen Resolution.

Thanks in Advance.

like image 502
Keyur Android Avatar asked May 17 '12 06:05

Keyur Android


2 Answers

Use the code from Screen Category or use getSize() method like:

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

as described here to get the screen size and and then set the font size accordingly using setTextSize() method, you can also consider using sp unit for font size.

like image 191
Imran Rana Avatar answered Jan 02 '23 12:01

Imran Rana


First, if you have not done so already, you should read this

http://developer.android.com/guide/practices/screens_support.html

To provide any resource, including styles that could apply to text, you should read the section Using configuration qualifiers

Another useful document here http://developer.android.com/guide/topics/resources/more-resources.html#Dimension should help you with selecting the right unit of measure for text, ideally you want to use sp's as explained in the excerpt:

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 the user's preference.

Hope that helps.

like image 33
Ian Warwick Avatar answered Jan 02 '23 11:01

Ian Warwick