多次组合3个相对布局(combine 3 relative layouts multiple times)

编程入门 行业动态 更新时间:2024-10-09 09:12:23
多次组合3个相对布局(combine 3 relative layouts multiple times)

我有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.

更多推荐

本文发布于:2023-08-07 16:52:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465285.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合   布局   combine   relative   multiple

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!