我需要 TextView 的实际文本宽度。
为了解释这是我的 TextView 描述:
- TextView 位于带有一些内部填充的 LinearLayout 中。
- TextView 设置为填充宽度并包裹高度。
- TextView 有一个 leftCompoundDrawable 集和一个 rightCompoundDrawable 集。
- 还有来自左侧复合可绘制对象的 TextView 文本的填充。
- TextView 中的文本可以是多行的。
我在 TextView 中的 text 的意思是 TextView 的属性,可以使用 XML 中的 android:text
属性或调用 setText 来设置() 在 TextView 上。
这是我正在做的。
[ScreenWidth]-[LeftCompundDrawableIntrinsic Width]-[RightDrawabaleIntrinsicWidth]-[LeftCompoundDrawablePadding]
是否有框架中的任何库存方法可以精确计算这一点?
这是描述我的 TextView 的图像
最佳答案
试试这个:
TextView tv;
Rect rc=new Rect();
//...
for(int i=0; i < tv.getLineCount(); i++)
{
tv.getLineBounds(line, rc);
Log.v(TAG, "Line #"+i+", left="+rc.left+", right="+rc.right);
}
关于android - 实际文本宽度android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4552272/