0
我使用这个库:https://github.com/mikepenz/MaterialDrawer 我有一个NavigationDrawer左侧导航项目和我有一个附加抽屉的权利:带有自定义片段的NavigationDrawer?
new DrawerBuilder()
.withActivity(this)
.withDrawerGravity(Gravity.END)
.append(result);
我也有一个RecyclerView和一些额外的视图片段内部:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/listBackground">
<android.support.v7.widget.RecyclerView
android:id="@+id/contactsList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
tools:listitem="@layout/fragment_contacts_item" />
<LinearLayout
android:id="@+id/layoutNoContacts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:orientation="vertical"
android:paddingBottom="128dp"
android:visibility="gone">
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:scaleType="fitCenter"
app:srcCompat="@drawable/sad" />
</LinearLayout>
此片段膨胀的布局和条目添加到RecyclerView。
这是我的主要布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@color/listBackground">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="80dp"
android:clickable="true" />
</RelativeLayout>
我怎样才能显示这个定制的片断这说明我在NavigationDrawer接触在任何时候,而不是导航项目?
非常感谢您的帮助!我已经添加了我的主布局文件,我需要在哪里添加它?我将如何把内容放在那里?只需要定期的FragmentTransaction? – user754730
片段是基于'android:name'属性静态添加的。 – EpicPandaForce
此布局应用于活动(活动内容布局),应在其中呈现抽屉。 如果您想动态添加片段 - 您应该用 替换标签的内容,并使用常规FragmentTransaction将Fragment添加到此Frame布局。查看更多碎片文档:https://developer.android.com/guide/components/fragments.html –