代码中设置布局属性 RelativeLayout.LayoutParams rl=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);rl.setMargins(30,0,0,0);button.setLayoutParams(rl);