在安卓系统中计算字符串的宽度

5
我需要知道给定字体句柄(或字体名称+字体大小+字体样式数据),文本字符串的宽度。
在Windows中,我过去常常使用GetTextExtentPoint()函数。
2个回答

10

使用此代码

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

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接