Setting width to wrap_content for TextView through code

后端 未结 6 1324
我在风中等你
我在风中等你 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 09:41

    I am posting android Java base multi line edittext.

    EditText editText = findViewById(R.id.editText);/* edittext access */
    
    ViewGroup.LayoutParams params  =  editText.getLayoutParams(); 
    params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    editText.setLayoutParams(params); /* Gives as much height for multi line*/
    
    editText.setSingleLine(false); /* Makes it Multi line */
    

提交回复
热议问题