Two solutions:
I,
1. obtain different font sizes based on different resolutions.
Create in res
In values-480x320/strings. XML, set <dimen name = "text_size"> 30px </dimen>
And
In values-800x400/strings. XML, set <dimen name = "text_size"> 30px </dimen>
The font size of 480x320 and X is 30px and 40px respectively;
This is called in a Java file.
Int sizeoftext = (INT) This. getresources (). getdimension (R. dimen. text_size );
II,
1. Obtain the view width in onsizechanged of the view. The default width is 320. Therefore, a scaling ratio is calculated.
Rate = (float) W/320 W is the actual width
2. Then, when setting the font size, paint. settextsize (INT) (8 * rate); 8 is the font size to be set when the resolution width is 320
Actual font size = default font size x rate
Java Code
- <Textview
- Android: layout_width ="Fill_parent"
- Android: layout_height ="Wrap_content"
- Android: text ="@ String/hello"
- Android: textsize ="@ Dimen/text_size"
- />
Layout multi-resolution adaptation
Original article: http://407827531.iteye.com/blog/973688