//转载一个布局文件,要向这个布局汇总动态添加一个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);
在代码中设置RelativeLayout布局中标签的android:layout_toLeftOf、android:layout_toRightOf等属性
最新推荐文章于 2024-04-22 04:14:56 发布