سؤال

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

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top