开发者

Actual Text Width android

I require actual Text width from a TextView.

To expalin this heres my TextView description:

  1. TextView lies in a LinearLayout with some internal padding.
  2. TextView is set to fill the width and wrap up the height.
  3. TextView has a leftCompoundDrawable set and a rightCompoundDrawable set.
  4. Theres also padding given to text of textview from left compound drawable.
  5. 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

Actual Text Width android


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜