Actual text width

I need the actual width of the text from a TextView.

To show this, my TextView description:

  • TextView is in LinearLayout with some internal addition.
  • TextView is configured to fill the width and complete the height.
  • TextView has a set of leftCompoundDrawable and a set of rightCompoundDrawable.
  • Theres also supplements the text of the text from the left compound file.
  • Text from a text view can be multi-line.

What I meant from TextView text is a TextView property that can be set using a property android:textfrom XML or by calling setText () in a TextView.

That's what I'm doing.

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

Is there any stock method from the framework that can pinpoint this?

Here is an image describing my TextView

Textview

+3
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);
}
0

Source: https://habr.com/ru/post/1782549/


All Articles