- 1. Get the screen size of the current device
- Displaymetrics displaymetrics = new Displaymetrics ();
- This.getwindowmanager (). Getdefaultdisplay (). Getmetrics (Displaymetrics);
- 2. Calculate the aspect ratio of the screen size set at the time of your development (this assumes that the screen size you set for development is 480*)
- int screenwidth = Displaymetrics.widthpixels;
- int screenheight = Displaymetrics.heightpixels;
- float ratiowidth = (float) screenwidth/ 480;
- float ratioheight = (float) screenheight/ 800;
- RATIO = Math.min (Ratiowidth, ratioheight);
- if (ratiowidth! = ratioheight) {
- if (RATIO = = ratiowidth) {
- Offset_left = 0;
- Offset_top = Math.Round ((screenheight- RATIO)/ 2);
- }Else {
- Offset_left = Math.Round ((screenwidth- 480 * RATIO)/ 2);
- Offset_top = 0;
- }
- }
- 3. Determine the size of the font based on the minimum aspect ratio calculated in the previous step (assuming that the font size is set to on the 480* 800 screen)
- Public static int text_size = Math.Round (* RATIO);
- 4. Set the size of the font in the application based on the font size calculated in the previous step
- Paint paint = new paint ();
- Paint.settextsize (text_size);
- Canvas.drawtext ("test", 0, 0, paint);
- from:http://blog.csdn.net/cq361106306/article/details/38400647
(RPM) Android self-painted font size paint.settextsize varies with resolution size