1. FontMetrics

  计算文本高度: fontMetrics.bottom - fontMetrics.top

2. measureText

  通过这个方法即可以轻松的获取到文字的的宽度。比如要获取一个TextView中文本的宽度:textView.getPaint().measureText(textView.getText().toString());

  如果是在自定义View中,可以直接使用 mPaint.measureText();

3. getTextBounds()

  利用此方法可以获取到包裹文字的最小矩形。

  Rect textRect = new Rect();

  mPaint.getTextBounds(textName, 0, textName.length(), textRect);

  通过  textRect.width() ,  textRect.height() 可以分别获取到包裹文字的最小矩形的宽高。

相关文章:

  • 2022-12-23
  • 2021-10-22
  • 2022-01-01
  • 2022-12-23
  • 2021-12-02
  • 2021-12-02
  • 2021-06-16
猜你喜欢
  • 2021-10-18
  • 2022-12-23
  • 2021-10-19
  • 2022-02-07
  • 2021-07-09
  • 2021-11-23
  • 2021-12-02
相关资源
相似解决方案