(RPM) Android self-painted font size paint.settextsize varies with resolution size

Source: Internet
Author: User

  1. 1. Get the screen size of the current device
  2. Displaymetrics displaymetrics = new Displaymetrics ();
  3. This.getwindowmanager (). Getdefaultdisplay (). Getmetrics (Displaymetrics);
  4. 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*)
  5. int screenwidth = Displaymetrics.widthpixels;
  6. int screenheight = Displaymetrics.heightpixels;
  7. float ratiowidth = (float) screenwidth/ 480;
  8. float ratioheight = (float) screenheight/ 800;
  9. RATIO = Math.min (Ratiowidth, ratioheight);
  10. if (ratiowidth! = ratioheight) {
  11. if (RATIO = = ratiowidth) {
  12. Offset_left = 0;
  13. Offset_top = Math.Round ((screenheight- RATIO)/ 2);
  14. }Else {
  15. Offset_left = Math.Round ((screenwidth- 480 * RATIO)/ 2);
  16. Offset_top = 0;
  17. }
  18. }
  19. 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)
  20. Public static int text_size = Math.Round (* RATIO);
  21. 4. Set the size of the font in the application based on the font size calculated in the previous step
  22. Paint paint = new paint ();
  23. Paint.settextsize (text_size);

    1. Canvas.drawtext ("test", 0, 0, paint);
    2. from:http://blog.csdn.net/cq361106306/article/details/38400647

(RPM) Android self-painted font size paint.settextsize varies with resolution size

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.