在android中文字实际高宽的获取

目前我比较常用的两种方式:

1、利用TextPaint类getTextBounds()方法(比较准确/精细)

  TextPaint tp=new TextPaint();

  Rect bounds = new Rect();

  tp.getTextBounds(showValue, 0, showValue.length()-1, bounds);

  获得的bounds对象里面就有关于文字的长宽

2、利用TextPaint类的measureText()方法(大致长度) 

3、利用文字长度乘以字体间隙度(一般都比实际长度长很多)

  tp.getFontSpacing() * (str.length()-1) 

posted @ 2012-11-28 10:32  crazywenza  阅读(417)  评论(0编辑  收藏  举报