首先需要生成一个LayoutParams对象
控件调用setLayoutParams,传入参数为这个LayoutParams对象
示例:
if(flag == TextView.VISIBLE){ RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); layoutParams.addRule(RelativeLayout.BELOW,R.id.labor3); returnBtn.setLayoutParams(layoutParams); }原文链接:https://www.f2er.com/xml/298429.html