NavigationDrawer里面有自定义片段?

时间:2016-12-27 13:44:04

标签: android android-fragments materialdrawer

我正在使用此库:https://github.com/mikepenz/MaterialDrawer 我左边有一个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中显示我的联系人而不是导航项?

1 个答案:

答案 0 :(得分:2)

你可以Android Drawer Layout而不是MaterialDrawer。 它就像一个带有自定义碎片的魅力。

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <!-- The navigation drawer -->
    <fragment android:name="com.example.YourFragment"
        android:id="@+id/left_drawer"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="match_parent" />
</android.support.v4.widget.DrawerLayout>
相关问题