我需要知道给定字体句柄(或字体名称+字体大小+字体样式数据),文本字符串的宽度。
在Windows中,我过去常常使用GetTextExtentPoint()函数。
在Windows中,我过去常常使用GetTextExtentPoint()函数。
使用此代码
Rect bounds = new Rect();
Paint textPaint = textView.getPaint();
textPaint.getTextBounds(text, 0, text.length(), bounds);
int height = bounds.height();
int width = bounds.width();