Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 实际文本宽度_Android_Width_Textview_Measure - Fatal编程技术网

Android 实际文本宽度

Android 实际文本宽度,android,width,textview,measure,Android,Width,Textview,Measure,我需要文本视图中的实际文本宽度 要对此进行解释,请参见我的文本视图说明: TextView位于带有一些内部填充的线性布局中 TextView设置为填充宽度和环绕高度 TextView有一个leftCompoundDrawable集合和一个rightCompoundDrawable集合 还有从左侧复合drawable为textview的文本提供的填充 文本视图中的文本可以是多行的 我从TextView的文本中所指的是TextView的属性,可以使用XML中的android:textproperty

我需要文本视图中的实际文本宽度

要对此进行解释,请参见我的文本视图说明:

  • TextView位于带有一些内部填充的线性布局中
  • TextView设置为填充宽度和环绕高度
  • TextView有一个leftCompoundDrawable集合和一个rightCompoundDrawable集合
  • 还有从左侧复合drawable为textview的文本提供的填充
  • 文本视图中的文本可以是多行的
  • 我从TextView的文本中所指的是TextView的属性,可以使用XML中的
    android:text
    property或在TextView上调用setText()来设置该属性

    这就是我正在做的

    [ScreenWidth]-[LeftCompundDrawableIntrinsic Width]-[RightDrawabaleIntrinsicWidth]-[LeftCompoundDrawablePadding]
    
    框架中是否有任何库存方法可以精确计算这一点?

    这是一张描述我的文本视图的图片

    试试这个:

    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);
    }
    
    TextView电视;
    Rect rc=新的Rect();
    //...
    对于(int i=0;i