In Android how to get the width of the Textview which is set to Wrap_Content

前端 未结 8 1648
时光取名叫无心
时光取名叫无心 2020-12-11 03:56

I am trying to add a text to the textview for which i have set the width as Wrap_content. I am trying to get the width of this textview. But its showing 0 in all the cases.

8条回答
  •  無奈伤痛
    2020-12-11 04:27

    You can not get the width of a View with dynamic size before the layout is completely built. That means there is no way you can get it in onCreate(). One way would be to create a class that inherits from TextView and overrides onSizeChanged().

提交回复
热议问题