在android中使用版面id将版面插入另一版面
我在xml文件(比如realtive.xml)中定义了一个相对布局。在另一个布局中,我在linearlayout(比如linear.xml)中有一个relativelayout标记。此真实布局为空,id为“rl”。单击linear.xml中的按钮后,我希望在id为“rl”的相对布局中设置relative.xml的内容在android中使用版面id将版面插入另一版面,android,Android,我在xml文件(比如realtive.xml)中定义了一个相对布局。在另一个布局中,我在linearlayout(比如linear.xml)中有一个relativelayout标记。此真实布局为空,id为“rl”。单击linear.xml中的按钮后,我希望在id为“rl”的相对布局中设置relative.xml的内容 如何操作?在该按钮的onClick()方法中,为新布局充气并将其添加到空的RelativeLayout: RelativeLayout rl = (RelativeLayout)
如何操作?在该
按钮的onClick()
方法中,为新布局充气并将其添加到空的RelativeLayout
:
RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl);
getLayoutInflater().inflate(R.layout.realtive, rl, true);
另外,如果您不想将父级RelativeLayout
从realtive.xml
添加到空的RelativeLayout
中,则使用合并
标记:
realtive.xml
在这里,您可以阅读有关“合并”标签的更多信息:为新布局充气并添加到RelativeLayout
getLayoutInflater().充气(资源、根、附件) 我认为你可以使用“include”标记,你可以简单地在另一个布局中包含一个布局文件。你可以根据自己的意愿隐藏这个包含的布局。。。
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Here is the content of the realtive.xml without the parent RelativeLayout-->
</merge>