use*_*135 1 android textview android-layout android-edittext
我是 Android 新手.. 我有一个大小为 250dp 的 textview.. 我正在尝试计算其中的文本宽度.. 但我找不到任何返回实际内容宽度的 API.. 有人可以帮忙吗?完毕。提前致谢。
您可以使用Paint持有的对象TextView来测量文本内容的宽度:
CharSequence text = textView.getText();
float width = textView.getPaint().measureText(text, 0, text.length());
还有一个版本可以测量文本内容的完整边界(左/右/上/下):
Rect bounds = new Rect();
CharSequence text = textView.getText();
textView.getPaint().getTextBounds(text, 0, text.length(), bounds);
//bounds now contains the rect of the actual text string
int width = bounds.getWidth();
| 归档时间: | 
 | 
| 查看次数: | 2802 次 | 
| 最近记录: |