【问题标题】:Actual Text Width android实际文本宽度android
【发布时间】:2011-05-31 22:29:55
【问题描述】:

我需要 TextView 的实际文本宽度。

为了解释这是我的 TextView 描述:

  1. TextView 位于带有一些内部填充的 LinearLayout 中。
  2. TextView 设置为填充宽度并包裹高度。
  3. TextView 有一个 leftCompoundDrawable 集和一个 rightCompoundDrawable 集。
  4. 还有从左侧复合可绘制对象中为 textview 的文本提供填充。
  5. 文本视图中的文本可以是多行的。

我的意思是 text 来自 TextView 是 TextView 的属性,可以使用 XML 中的 android:text 属性或通过调用 TextView 上的 setText() 来设置。

这就是我正在做的事情。

[ScreenWidth]-[LeftCompundDrawableIntrinsic Width]-[RightDrawabaleIntrinsicWidth]-[LeftCompoundDrawablePadding]

是否有任何来自框架的股票方法可以精确计算?

这是描述我的 TextView 的图像

【问题讨论】:

    标签: android width textview measure


    【解决方案1】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-26
      • 1970-01-01
      • 1970-01-01
      • 2011-10-08
      • 2015-05-25
      • 1970-01-01
      • 2015-10-04
      • 1970-01-01
      相关资源
      最近更新 更多