开发者

How to get maximum width of multiline TextView in android?

开发者 https://www.devze.com 2023-03-13 03:45 出处:网络
I am new in android and facing the problem to get the maximum width of the multiline TextView. I used textview.ge开发者_StackOverflowtWidth() and textview.getMeasuredWidth() but both gives garbage va

I am new in android and facing the problem to get the maximum width of the multiline TextView.

I used textview.ge开发者_StackOverflowtWidth() and textview.getMeasuredWidth() but both gives garbage value.

I used also textview.length(), but retuns zero.

Please note that i have not set the maximum width of the TextView.I want to get it runtime.


TextView_name.setLayoutParams(new LayoutParams(250,LayoutParams.WRAP_CONTENT));

by using the above code we can set the width for textview dynamically


I would try to use getWidth(). If you want to do that though, you have to be careful when you call it. It only makes sense after the view hierarchy is laid out. That means that trying to check onCreate, onStart or even onResume will probably not get the results that you want. As an experiment, you can call it in a click handler of a button and you should see the expected value correctly being returned. I can't really say any more about where you should get it without knowing what you want to use it for.

0

精彩评论

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

关注公众号