我有 3 个相对布局,我需要创建一个 setcontetntview,它是这些布局的组合,每个布局添加 3 次并共享相等的屏幕空间,并且需要以编程方式完成。我首先创建了一个新布局,只添加了 2 个屏幕,
RelativeLayout primaryLayout = new RelativeLayout(this);
LayoutInflater layoutInflater = (LayoutInflater)this.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
RelativeLayout newLayout = (RelativeLayout)layoutInflater.inflate(R.layout.layout3, null, false);
RelativeLayout newLayout1 = (RelativeLayout)layoutInflater.inflate(R.layout.layout4, null, false);
primaryLayout.addView(newLayout);
primaryLayout.addView(newLayout1);
setContentView(primaryLayout);
这仅显示layout4。另外,如果我再次添加相同的布局,它给出的错误说明指定的孩子已经有一个父母,你必须先在孩子的父母上调用 removeview()。请帮忙!