Android 在抽屉布局中将多个布局添加到导航抽屉
我有一个抽屉布局和两个碎片。我想在导航抽屉上添加那个片段。碎片有两种容器布局:@+id/container1用于碎片1,@+id/container2用于碎片2。但我只能添加一个,没有显示另一个片段。当我为fragment1设置container1,为fragment2设置container2时,只显示fragment1。然后我将container1设置为fragment2,将container2设置为fragment1。但此时只显示片段2。如何在导航抽屉上添加这两种布局 以下是我的主要布局:Android 在抽屉布局中将多个布局添加到导航抽屉,android,android-layout,android-fragments,navigation-drawer,drawerlayout,Android,Android Layout,Android Fragments,Navigation Drawer,Drawerlayout,我有一个抽屉布局和两个碎片。我想在导航抽屉上添加那个片段。碎片有两种容器布局:@+id/container1用于碎片1,@+id/container2用于碎片2。但我只能添加一个,没有显示另一个片段。当我为fragment1设置container1,为fragment2设置container2时,只显示fragment1。然后我将container1设置为fragment2,将container2设置为fragment1。但此时只显示片段2。如何在导航抽屉上添加这两种布局 以下是我的主要布局:
<android.support.v4.widget.DrawerLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">
<!-- my main content -->
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/tool_bar"
style="@style/ToolBarStyle"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways" />
<LinearLayout
android:orientation="vertical"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@color/color_accent_pink">
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/newsRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:clickable="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
<!-- my navigation drawer -->
<RelativeLayout
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@color/myDrawerBackground">
<!-- container layout for fragment1 -->
<RelativeLayout
android:id="@+id/container1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/merhabaText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:layout_marginRight="40dp"
android:layout_alignParentRight="true"
android:text="Hello!"/>
</RelativeLayout>
<!-- container layout for fragment2 -->
<RelativeLayout
android:id="@+id/container2"
android:layout_below="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/merhabaText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="400dp"
android:layout_marginRight="40dp"
android:layout_alignParentRight="true"
android:text="Hi!"/>
</RelativeLayout>
</RelativeLayout>
这可能只是你的问题而不是你的项目中的一个错误,但我注意到你的第二个容器的下面有一行
android:layout_=“@+id/container”
,看起来它实际上应该是android:layout_=“@id/container1”
我使用了@id/container1,但它没有解决问题。没有任何更改。这可能只是您的问题中的错误,而不是您的项目中的错误,但我注意到您的第二个容器在=“@+id/container”下面有一行android:layout\u=“@id/container1”
我使用了@id/container1,但它没有解决问题。没有什么变化。