1.新建view
CheckBox checkBox = new CheckBox(context);
2.添加到布局
relativeLayoutHand.addView(checkBox);
3.取出这个已添加view的参数,设置参数
RelativeLayout.LayoutParams layoutForCheckBox = (android.widget.RelativeLayout.LayoutParams) checkBox.getLayoutParams();
layoutForCheckBox.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);//靠右
checkBox.setLayoutParams(layoutForCheckBox);
注:linearLayout.setOrientation(VERTICAL); 动态设置线性布局垂直