I require actual Text width from a TextView.
To expalin this heres my TextView description:
- TextView lies in a LinearLayout with some internal padding.
- TextView is set to fill the width and wrap up the height.
- TextView has a leftCompoundDrawable set and a rightCompoundDrawable set.
- Theres also padding given to text of textview from left compound drawable.
- Text from text view can be multiline.
What I meant from text from TextView is property of TextView which can be set using android:text
property from XML or by calling setText() on TextView.
Heres what I am doing.
[ScreenWidth]-[LeftCompu开发者_StackOverflowndDrawableIntrinsic Width]-[RightDrawabaleIntrinsicWidth]-[LeftCompoundDrawablePadding]
is there any stock method from framework which can precisely caluclate this ?
Heres an image describing my TextView
Try this:
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);
}
精彩评论