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 –