7

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.

Ajeet Choudhary
  • 1,751
  • 1
  • 11
  • 37
Keyur Android
  • 337
  • 2
  • 5
  • 19
  • 1
    check [http://stackoverflow.com/questions/10595795/button-and-size-of-text/10596355#10596355](http://stackoverflow.com/questions/10595795/button-and-size-of-text/10596355#10596355) – silwar May 17 '12 at 07:45
  • 1. use **sp** 2. check http://stackoverflow.com/questions/2617266/how-to-adjust-text-font-size-to-fit-textview – jerry.hsu Jun 05 '12 at 10:36
  • check this http://stackoverflow.com/questions/16706076/font-size-and-images-for-different-devices – Bhavesh Jethani Jul 24 '14 at 08:10

7 Answers7

5

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.

Community
  • 1
  • 1
Imran Rana
  • 11,447
  • 7
  • 42
  • 51
2

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.

Ian Warwick
  • 4,744
  • 3
  • 24
  • 27
1

Hi create the folders as below in your resources folder and then copy your XML files in to it now you can check the palette window it will show the screens for different sizes based on that u can modify the screen size .

layout-large, layout-small, layout-xlarge ,

Now it supports to all types of screen sizes and your Font size will be clear based on screen size. For more information regarding to Supporting Multiple Screens check the android documentation .

Community
  • 1
  • 1
androidgeek
  • 3,299
  • 1
  • 13
  • 27
1

automatic adjust font size as per screen by using this code

Display display;
Point size;
int width, height;
float txtsize;

declare and use in oncreate()

display = getWindowManager().getDefaultDisplay();
         size = new Point();
        display.getSize(size);
         width = size.x;
         height = size.y;
         txtsize=height*0.024f;

/* if your screen height is 854 its use font size 20.4*/

to set size to textview just use this code..

 textView.setTextSize(txtsize);
0

one way to do this is make necessary folders like layout-large, layout-small, layout-normal,layout-xlarge in res folder . and put your xmls into those folder and then change whatever you want to do with text view and anything

Dhruvil Patel
  • 2,836
  • 2
  • 20
  • 39
0

you should use sp unit for font sizes instead of dip or dp. sp is scale independent pixels which adjust themselves according to screen pixel density. here is the exact difference.

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.

N-JOY
  • 10,164
  • 7
  • 47
  • 69
-3

Go to your xml file and add textsize as:

android:textSize="20sp" 

This will increase your font size

Taryn
  • 224,125
  • 52
  • 341
  • 389
Abhinai
  • 1,032
  • 2
  • 13
  • 20