计算Android上字符串的宽度

exe*_*ook 4 android text-rendering

我需要知道给定字体句柄的文本字符串的宽度(或字体名称+字体大小+字体样式数据).

在Windows中我以前使用GetTextExtentPoint()

Sha*_*wat 9

使用此代码

 Rect bounds = new Rect(); 
 Paint textPaint = textView.getPaint();
 textPaint.getTextBounds(text, 0, text.length(), bounds); 
 int height = bounds.height(); 
 int width = bounds.width();
Run Code Online (Sandbox Code Playgroud)