To adapt to which resolution you add values-xxxxxxx (such as: values-values-1024x600) folder under your project res, the new Dimens.xml file format in the folder is 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(Pixel):Screen actual pixel, often said resolution1024*768pixels, is horizontal1024PX,Longitudinal768px, different devices show the same effect.
inch(Inches):Physical dimensions of the screen,per inch equals2.54Cm.
mm(Mm):The physical size of the screen.
PT(Point) :The physical size of the screen.1/72Inches.
Dp/dip:160 dot on the monitor, 1DP = 1pxdp and px&NBSP;
sp : best fortextsize Java: Float dimen =resources.getdimen (r.dimen.some_name)
Xml example:
· <?xmlversion= "1.0" encoding= "Utf-8"?>
· <resources>
· <dimenname= "One_pixel" >1px</dimen>
· <dimenname= "double_density" >2dp</dimen>
· <dimenname= "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/< Span style= "color: #c00000;" >320)
- return rate<? 14:rate;
- }
Android Font Size Adaptive