re-setting a TextView height programmatically

后端 未结 6 1088
甜味超标
甜味超标 2020-12-24 11:20

I want to reset a textView height after I have added it to the main window in the xml file.

inside a RelativeLayout,

  

        
6条回答
  •  暖寄归人
    2020-12-24 11:59

    the sample way for this if you want to use dimen

    first, you should set size in dimen XML file.

    50dp
    50dp
    

    and

    text_l.getLayoutParams().height = 
         getResources().getDimensionPixelSize(R.dimen.text_height);
    
    text_l.getLayoutParams().width = 
         getResources().getDimensionPixelSize(R.dimen.text_width);
    

    Or

    if you want to set just int (for example we wanna set 50dp height and 100dp width)

    text_l.getLayoutParams().height = 50 * 3;
    text_l.getLayoutParams().width= 100 * 3;
    

提交回复
热议问题