如何在支持设计库中使用Framelayout和NavigationView

问题描述 投票:0回答:1

如何在导航视图中添加framelayout,我将framelayout用作抽屉中碎片的容器。

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include layout="@layout/toolbar"/>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:elevation="7dp">

        <android.support.design.internal.NavigationMenuView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true">

            <FrameLayout
                android:id="@+id/content_frame"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>


        </android.support.design.internal.NavigationMenuView>
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

这是我的实施。这是正确的方法吗?

android android-layout android-framelayout android-design-library navigationview
1个回答
2
投票

这可能是一个简单的实现,你可以检查this post了解更多信息:

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    <android.support.design.widget.NavigationView
            android:id="@+id/drawer"
            android:layout_width="@dimen/navigation_drawer_width"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:headerLayout="@layout/header_view"
            app:menu="@menu/drawer_menu" />

</android.support.v4.widget.DrawerLayout>
© www.soinside.com 2019 - 2024. All rights reserved.