我需要知道给定字体句柄(或字体名称 + 字体大小 + 字体样式数据)的文本字符串的宽度。
在 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();
关于android - 在Android上计算字符串的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15355950/