在代码中设置RelativeLayout布局中标签的android:layout_toLeftOf、android:layout_toRightOf等属性

 

//转载一个布局文件,要向这个布局汇总动态添加一个button
RelativeLayout relativeLayout(RelativeLayout)getLayoutInflater().inflate(R.layout.main,null);
//装载要动态添加的按钮布局
Button button = (Button)getLayoutInflater().inflate(R.layout.button,null);
//创建一个LayoutParams对象

RelativeLayoutLayoutParamslayoutParams= new RelativeLayout。LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);

layoutParams.addRule(RelativeLayout.RIGHT_OF,R.id.button1);

layoutParams.addRule(RelativeLayout.BELOW,R.id.button);
button.setLayoutParams(layoutParams);

relativeLayout.addView(button);
posted @ 2018-10-08 16:36  新感觉  阅读(3404)  评论(0编辑  收藏  举报