Setting width to wrap_content for TextView through code

后端 未结 6 1422
我在风中等你
我在风中等你 2020-12-25 09:24

Can anyone help me how to set the width of TextView to wrap_content through code and not from XML?

I am dynamically creating a TextVi

6条回答
  •  甜味超标
    2020-12-25 10:04

    A little update on this post: if you are using ktx within your Android project, there is a little helper method that makes updating LayoutParams a lot easier.

    If you want to update e.g. only the width you can do that with the following line in Kotlin.

    tv.updateLayoutParams { width = WRAP_CONTENT }
    

提交回复
热议问题