xgjblog

 

//转载一个布局文件,要向这个布局汇总动态添加一个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);

分类:

技术点:

相关文章:

  • 2021-08-16
  • 2021-11-17
  • 2021-10-28
  • 2021-09-25
  • 2021-12-10
  • 2021-11-17
  • 2021-09-25
  • 2021-06-21
猜你喜欢
  • 2021-09-25
  • 2021-09-25
  • 2021-11-17
  • 2021-09-25
  • 2021-11-17
  • 2021-11-23
相关资源
相似解决方案