【发布时间】:2018-08-08 14:08:41
【问题描述】:
我需要知道给定字体句柄(或字体名称 + 字体大小 + 字体样式数据)的文本字符串的宽度。
在 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();
【讨论】:
可以获取TextView的TypeFace:http://developer.android.com/reference/android/widget/TextView.html#getTypeface() 但很难获得字体系列,请检查以下内容: Check the family of a Typeface object in Android
【讨论】: