android 字体

  1. public static void changeViewSize(ViewGroup viewGroup,int screenWidth,int screenHeight) {//传入Activity顶层Layout,屏幕宽,屏幕高
  2. 3. int adjustFontSize = adjustFontSize(screenWidth,screenHeight);
  3. 4. for(int i = 0; i<viewGroup.getChildCount(); i++ ){
  4. 5. View v = viewGroup.getChildAt(i);
  5. 6. if(v instanceof ViewGroup){
  6. 7. changeViewSize((ViewGroup)v,screenWidth,screenHeight);
  7. 8. }else if(v instanceof Button){//按钮加大这个一定要放在TextView上面,因为Button也继承了TextView
  8. 9. ( (Button)v ).setTextSize(adjustFontSize+2);
  9. 10. }else if(v instanceof TextView){
  10. 11. if(v.getId()== R.id.title_msg){//顶部标题
  11. 12. ( (TextView)v ).setTextSize(adjustFontSize+4);
  12. 13. }else{
  13. 14. ( (TextView)v ).setTextSize(adjustFontSize);
  14. 15. }
  15. 16. }
  16. 17. }
  17. 18. }
  18. 19.
  19. 20.
  20. 21.//获取字体大小
  21. 22.public static int adjustFontSize(int screenWidth, int screenHeight) {
  22. 23. screenWidth=screenWidth>screenHeight?screenWidth:screenHeight;
  23. 24. /**
  24. 25. * 1. 在视图的 onsizechanged里获取视图宽度,一般情况下默认宽度是320,所以计算一个缩放比率
  25. 26. rate = (float) w/320 w是实际宽度
  26. 27. 2.然后在设置字体尺寸时 paint.setTextSize((int)(8*rate)); 8是在分辨率宽为320 下需要设置的字体大小
  27. 28. 实际字体大小 = 默认字体大小 x rate
  28. 29. */
  29. 30. int rate = (int)(5*(float) screenWidth/320); //我自己测试这个倍数比较适合,当然你可以测试后再修改
  30. 31. return rate<15?15:rate; //字体太小也不好看的
  31. 32.}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值