问题
I need to know width of text string given font handle (or font name + font size + font style data).
in Windows I used to use GetTextExtentPoint()
回答1:
use this code
Rect bounds = new Rect();
Paint textPaint = textView.getPaint();
textPaint.getTextBounds(text, 0, text.length(), bounds);
int height = bounds.height();
int width = bounds.width();
回答2:
You can get TypeFace of TextView: http://developer.android.com/reference/android/widget/TextView.html#getTypeface() but it's hard to get font family, check also this: Check the family of a Typeface object in Android
来源:https://stackoverflow.com/questions/15355950/calculating-width-of-a-string-on-android