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

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) 

相关文章:

  • 2021-12-26
  • 2022-12-23
  • 2021-09-28
  • 2021-09-27
  • 2021-10-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-12
  • 2021-12-16
  • 2021-10-22
  • 2021-08-17
  • 2021-07-29
  • 2021-12-03
相关资源
相似解决方案