Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 包括来自其他布局的线性布局_Android_Xml_Layout - Fatal编程技术网

Android 包括来自其他布局的线性布局

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_

我在android(R.layout.items)中有一个
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文件中的方法。