Android RelativeLayout用纯java设置margin的办法
RelativeLayout rl = new RelativeLayout(this);MarginLayoutParams mp = new MarginLayoutParams(20,20); //item的宽高
mp.setMargins(0, 0, 25, 0);//分别是margin_top那四个属性
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(mp);
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
Button bt = new Button(this);
bt.setLayoutParams(lp);
rl.addView(bt);
摘自 bingdongguke的专栏
补充:综合编程 , 其他综合 ,