我有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()。 请帮忙!
I have 3 relative layouts and i need to create a single setcontetntview which is a combination of these layouts each added 3 times and sharing equal screen space and it needs to be done programatically. I started by creating a new layout adding just 2 screens,
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);This is displaying only the layout4. Also, if i add same layout again, its giving error stating the specified child already has a parent, you must call removeview() on the child parent first. Please help!
最满意答案
因此,仅显示layout4的原因是primaryLayout是相对布局。 除非你指定一些东西告诉它在那个布局中的位置,否则它都在左上角。 所以一切都被放在一起。
您无法多次添加相同的布局。 您必须为所需的每个版本重新填充一次,然后添加结果。 它就像OOP- RelativeLayout是布局的一个实例,膨胀实例化一个新的布局。
THe reason its displaying only layout4 is that the primaryLayout is a relative layout. Unless you specify something telling it where they go in that layout, it all goes in the upper left corner. So everything is being put on top of one another.
You can't add the same layout multiple times. You'd have to reinflate it once for every version you want, and add the results. Its like OOP- the RelativeLayout is an instance of the layout, inflating instantiates a new one.
更多推荐
发布评论