Two workarounds:
One
1, first, according to different resolutions to obtain a different font size.
Create in Res
Values-480x320/strings.xml inside set <dimen name= "Text_size" >30px</dimen>
And
Values-800x400/strings.xml inside set <dimen name= "Text_size" >30px</dimen>
For 480x320 and 800x400 resolution respectively, the font size is 30px and 40px;
This is called in the Java file
int sizeoftext = (int) this.getresources (). Getdimension (R.dimen.text_size);
Two
1. Get the view width in the onsizechanged of the view, usually the default width is 320, so calculate a zoom ratio
Rate = (float) w/320 W is the actual width
2. Then paint.settextsize (int) (8*rate) when setting the font size; 8 is the font size to be set at a resolution width of 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