zoukankan      html  css  js  c++  java
  • ( 转 ) Android自绘字体大小paint.settextsize随分辨率大小变化

    1. 1.获取当前设备的屏幕大小  
    2.   
    3. DisplayMetrics displayMetrics = new DisplayMetrics();  
    4. this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);  
    5.   
    6. 2.计算与你开发时设定的屏幕大小的纵横比(这里假设你开发时定的屏幕大小是480*800)  
    7.   
    8. int screenWidth = displayMetrics.widthPixels;  
    9. int screenHeight = displayMetrics.heightPixels;  
    10. float ratioWidth = (float)screenWidth / 480;  
    11. float ratioHeight = (float)screenHeight / 800;  
    12.           
    13. RATIO = Math.min(ratioWidth, ratioHeight);  
    14. if (ratioWidth != ratioHeight) {  
    15.     if (RATIO == ratioWidth) {  
    16.     OFFSET_LEFT = 0;  
    17.     OFFSET_TOP = Math.round((screenHeight - 800 * RATIO) / 2);  
    18.     }else {  
    19.     OFFSET_LEFT = Math.round((screenWidth - 480 * RATIO) / 2);  
    20.     OFFSET_TOP = 0;  
    21.     }  
    22. }  
    23.   
    24. 3.根据上一步计算出来的最小纵横比来确定字体的大小(假定在480*800屏幕下字体大小设定为35)  
    25.   
    26. public static int TEXT_SIZE = Math.round(35 * RATIO);  
    27.   
    28. 4.根据上一步计算的字体大小来设定应用程序中字体的大小  
    29.   
    30. Paint paint = new Paint();  
    31. paint.setTextSize(TEXT_SIZE);  
    1. canvas.drawText("test", 0, 0, paint);  
    2. from:http://blog.csdn.net/cq361106306/article/details/38400647
  • 相关阅读:
    hadoop之hdfs架构详解
    hadoop之hdfs命令详解
    hadoop高可用安装和原理详解
    mysql事务
    mysql之innodb-锁
    [转]网络基本功02-细说交换机
    python随用随学20200221-生成器中的send(),throw()和close()方法
    python随用随学20200118-函数的高级特性
    [转载]网络基本功01-细说网络传输
    selenium+chrome抓取淘宝宝贝-崔庆才思路
  • 原文地址:https://www.cnblogs.com/woaixingxing/p/5780014.html
Copyright © 2011-2022 走看看