5

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()

exebook
  • 32,014
  • 33
  • 141
  • 226

2 Answers2

10

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();
Shailendra Singh Rajawat
  • 8,172
  • 3
  • 35
  • 40
0

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

Community
  • 1
  • 1
maszter
  • 3,680
  • 6
  • 37
  • 53