Android NavigationDrawer是否包含自定义片段?
我正在使用这个库: 我在左侧有一个导航抽屉,里面有导航项目,在右侧有一个额外的抽屉:Android NavigationDrawer是否包含自定义片段?,android,android-fragments,materialdrawer,Android,Android Fragments,Materialdrawer,我正在使用这个库: 我在左侧有一个导航抽屉,里面有导航项目,在右侧有一个额外的抽屉: new DrawerBuilder() .withActivity(this) .withDrawerGravity(Gravity.END) .append(result); 我还有一个片段,里面有一个RecyclerView和一些附加视图: <?xml version="1.0" encoding="utf-8"?> <RelativeLa
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中显示我的联系人而不是导航项?您可以使用is代替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>
您可以使用is代替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>
非常感谢您的帮助!我已经添加了我的主布局文件,我需要在哪里添加它?我该如何把内容放进去?仅使用常规FragmentTransaction?片段是基于android:name
属性静态添加的。此布局应在活动(活动内容布局)中使用,您的抽屉应显示在活动中。若你们想动态地添加片段——你们应该用替换标签的内容,并用常规的FragmentTransaction将片段添加到这个框架布局中。请参阅片段文档中的更多内容:非常感谢您的帮助!我已经添加了我的主布局文件,我需要在哪里添加它?我该如何把内容放进去?仅使用常规FragmentTransaction?片段是基于android:name
属性静态添加的。此布局应在活动(活动内容布局)中使用,您的抽屉应显示在活动中。若你们想动态地添加片段——你们应该用替换标签的内容,并用常规的FragmentTransaction将片段添加到这个框架布局中。请参阅碎片文档中的更多内容: