Android 包括来自其他布局的线性布局
我在android(R.layout.items)中有一个Android 包括来自其他布局的线性布局,android,xml,layout,Android,Xml,Layout,我在android(R.layout.items)中有一个layout.xml面板: ..... 在这个面板中,我有一些线性布局,我想通过编程动态地添加到另一个布局(r.layout.other): 使用充气,我只能添加r.layout资源,而不能添加r.id。我想将单个视图(例如panel1)添加到r.layout.other。有什么想法吗?使用这个概念 LinearLayout global_panel = new LinearLayout (this); global_
layout.xml
面板:
.....
在这个面板中,我有一些线性布局
,我想通过编程动态地添加到另一个布局(r.layout.other)
:
使用充气,我只能添加r.layout
资源,而不能添加r.id
。我想将单个视图(例如panel1)添加到r.layout.other
。有什么想法吗?使用这个概念
LinearLayout global_panel = new LinearLayout (this);
global_panel.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
global_panel.setGravity(Gravity.FILL);
global_panel.setBackgroundResource(R.drawable.back);
使用这个概念
LinearLayout global_panel = new LinearLayout (this);
global_panel.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
global_panel.setGravity(Gravity.FILL);
global_panel.setBackgroundResource(R.drawable.back);
将该
LinearLayout
另存为单独的panel.xml
,并使用
标记调用不同的layout.xml
文件,如下所示:
<LinearLayout ... >
<include layout="@layout/panel" />
</LinearLayout>
将
线性布局
另存为单独的面板.xml
,并使用
标记调用不同的布局.xml
文件,如下所示:
<LinearLayout ... >
<include layout="@layout/panel" />
</LinearLayout>
我不能用其他xml保存每个面板,因为有很多;不可能从单个res R.layout.items R.layout.other以友好方式添加到R.layout.other?这是调用公共布局部分并包含在其他xml文件中的方法。我无法将每个面板保存在其他xml中,因为有很多;无法从单个res R.layout.items R.layout.other以友好方式添加到R.layout.other?这是调用公共布局部分并包含在其他xml文件中的方法。