How to set margins for TextView programmatically?

后端 未结 4 1518
清酒与你
清酒与你 2020-12-14 05:46
TextView tv1 = new TextView(this);      
tv1.setPadding(5, 0, 5, 0);
tv1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
tv1         


        
4条回答
  •  既然无缘
    2020-12-14 06:14

    set to LayoutParams.

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.setMargins(10,10,10,10);
    tv1.setLayoutParams(params);
    

提交回复
热议问题