If you want to adapt to which resolution in your project RES add values-xxxxxxx (such as: values-values-1024x600) folder, in the folder new Dimens.xml file format as follows: <?xml version= "1.0 "Encoding=" Utf-8 "?><resources> <dimen name=" text_size ">40sp</dimen> </resources> Layout file Reference: <textview android:layout_width= "fill_parent" android:layout_height= "Wrap_content" Android: text= "ABCDEFG" android:textsize= "@dimen/text_size"/> A brief description of font units:
px (pixels): The actual pixels of the screen, often said resolution 1024*768pixels, is the transverse 1024px, portrait 768px, different devices display the same effect.
inch (inch): The physical size of the screen, equal to 2.54 centimeters per inch.
mm (mm): The physical size of the screen.
PT (point): The physical size of the screen. 1/72 inches.
Dp/dip : pixels independent of density, a unit of abstraction based on screen density. 1DP = 1px on a monitor 160 dots per inch. However, the ratio of DP and PX varies with the screen density, and different devices have different display effects.
SP : A scale-independent pixel that is used primarily for font display of best for TEXTSIZE, as a unit of text-related size.
Xml:android:textsize= "@dimen/some_name"
Java:float dimen = resources.getdimen (r.dimen.some_name)
XML Example:
· <?xml version= "1.0" encoding= "Utf-8"?>
· <resources>
· <dimen name= "One_pixel" >1px</dimen>
· <dimen name= "Double_density" >2dp</dimen>
· <dimen name= "SIXTEEN_SP" >16sp</dimen>
· </resources>
Calculate a certain percentage of font size by screen size:
- public static int getfontsize (int screenwidth, int screenheight) {
- screenwidth=screenwidth>screenheight?screenwidth:screenheight;
- int rate = (int) (5* (float) screenwidth/320);
- Return rate<14?14:rate;
- }
Android Font Size Adaptive