Setting width to wrap_content for TextView through code

后端 未结 6 1412
我在风中等你
我在风中等你 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-25 09:50

    There is another way to achieve same result. In case you need to set only one parameter, for example 'height':

    TextView textView = (TextView)findViewById(R.id.text_view);
    ViewGroup.LayoutParams params = textView.getLayoutParams();
    params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    textView.setLayoutParams(params);
    

提交回复
热议问题