Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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
Java 如何在Android中将一个版面添加到另一个版面_Java_Android_Android Layout - Fatal编程技术网

Java 如何在Android中将一个版面添加到另一个版面

Java 如何在Android中将一个版面添加到另一个版面,java,android,android-layout,Java,Android,Android Layout,如何将一个版面添加到另一个版面 如何将Java编写的布局添加到另一个布局。在这种情况下,我想添加新的RevAppBarLayout().getRevAppBarLayout(this)到名为抽屉的抽屉布局 DrawerLayout drawer = new DrawerLayout(this); drawer.addView(inflatedLayout); 如果它是一个XML片段,下面介绍如何执行此操作: AppBarLayout revAppBarLayout = new RevTool

如何将一个版面添加到另一个版面

如何将Java编写的布局添加到另一个布局。在这种情况下,我想添加
新的RevAppBarLayout().getRevAppBarLayout(this)到名为抽屉的抽屉布局

DrawerLayout drawer = new DrawerLayout(this);
drawer.addView(inflatedLayout);

如果它是一个XML片段,下面介绍如何执行此操作:

AppBarLayout revAppBarLayout = new RevToolBar().getRevAppBarLayout( this );

LayoutInflater inflater = LayoutInflater.from(context);
 View inflatedLayout= inflater.inflate(R.layout.yourLayout, null, false);
 drawer.addView(inflatedLayout);

您是否将抽屉添加到布局中?因为它不是从布局中检索的,所以您正在将其动态实例化为一个新对象


而且,您不需要充气机来向其他布局添加布局或视图。如果是活动,则使用
findViewById(R.id.layoutContainer)获取布局(RelativeLayout、FrameLayout等)然后使用addView将任何视图添加到此布局。

为什么片段很重要
View.addView
是方法,您似乎已经在使用它了
AppBarLayout revAppBarLayout = new RevToolBar().getRevAppBarLayout( this );

LayoutInflater inflater = LayoutInflater.from(context);
 View inflatedLayout= inflater.inflate(R.layout.yourLayout, null, false);
 drawer.addView(inflatedLayout);