android - 带框架布局的抽屉导航

标签 android android-fragments navigation-drawer appbar

我有一个抽屉导航 Activity ,其中包含一个用 fragment 替换的框架布局。但该 fragment 与应用栏重叠。我还想抽屉导航是否在应用栏下方启动。我怎样才能实现这一目标?

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:menu="@menu/activity_main_drawer" />

    <FrameLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/containerView">
    </FrameLayout>

</android.support.v4.widget.DrawerLayout>

最佳答案

将 app_bar 获取到 DrawerLayout 之外。

<?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">

    <include
        android:id="@+id/app_bar"
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <android.support.v4.widget.DrawerLayout 
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/app_bar"
        android:fitsSystemWindows="true"
        tools:openDrawer="start">

        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            app:menu="@menu/activity_main_drawer" />

        <FrameLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/containerView">
        </FrameLayout>

    </android.support.v4.widget.DrawerLayout>
</RelativeLayout>

关于android - 带框架布局的抽屉导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42223481/

相关文章:

java - 自定义ArrayAdapter,super无法解析

java - Ho 从另一个 Activity 调用自己的 toast 消息

android - ViewPager 中的部 fragment 段在屏幕底部被截断(Android)

android - 转换异常 : after Updating Fragment from ViewPager

android - 如何使用导航 Controller 设置抽屉导航并处理单个菜单项

深度导航中的 Android 抽屉导航

android - 将 float 操作按钮变形为相关操作

Android语音识别和录音同时进行

java - 抽屉导航上方的图像(使用 fragment )

android - 抽屉导航在onDrawerOpened时隐藏键盘