计算Android上字符串的宽度

时间:2013-03-12 07:57:00

标签: android text-rendering

我需要知道给定字体句柄的文本字符串的宽度(或字体名称+字体大小+字体样式数据)。

Windows中的

我过去常常使用GetTextExtentPoint()

2 个答案:

答案 0 :(得分:9)

使用此代码

 Rect bounds = new Rect(); 
 Paint textPaint = textView.getPaint();
 textPaint.getTextBounds(text, 0, text.length(), bounds); 
 int height = bounds.height(); 
 int width = bounds.width();

答案 1 :(得分:0)

你可以获得TextView的TypeFace:http://developer.android.com/reference/android/widget/TextView.html#getTypeface() 但是很难获得字体系列,请查看: Check the family of a Typeface object in Android