【问题标题】:Android Dual Drawers - Navigation with Navigation View and Navigation FragmentAndroid Dual Drawers - 带有导航视图和导航片段的导航
【发布时间】:2016-05-18 12:07:05
【问题描述】:

开发遗产追踪应用程序!

我需要在左侧有一个导航抽屉和另一个带复选框的导航抽屉。

Left side Drawer 是使用 Android Studio 和我实现的右侧代码生成的。

只有其中一个正在显示。我如何获得右侧的导航视图和左侧的 Fragment Drawer。


下面的 XML

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:orientation="vertical">



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

    <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:headerLayout="@layout/nav_header_main"
            app:menu="@menu/activity_main_drawer" />


    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:name="org.janastu.dualnavigation.FragmentDrawer"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer" />


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

【问题讨论】:

    标签: android android-layout android-fragments navigation


    【解决方案1】:

    如果您的app_bar_mainAppBarLayoutToolbar,那么我会假设:

    1. 您不希望它填满整个屏幕。
    2. 您不希望它被视为DrawerLayout 的主要内容。

    在那个笔记上,试试这个:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical">
    
        <!-- Your Toolbar or Appbar. I've included what it should look like here
             to point out that layout_height SHOULD NOT BE match_parent.-->
        <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.v4.widget.DrawerLayout
            android:id="@+id/drawer_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <!--Main Content-->
            <FrameLayout
                android:id="@+id/fullscreen_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"/>
    
            <!-- Left side drawer layout -->
            <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:headerLayout="@layout/nav_header_main"
                app:menu="@menu/activity_main_drawer" />
    
            <!-- Right side drawer layout. Important to note that fragment_navigation_drawer
                 should have a background colour. -->   
            <fragment
                android:id="@+id/fragment_navigation_drawer"
                android:name="org.janastu.dualnavigation.FragmentDrawer"
                android:layout_width="@dimen/nav_drawer_width"
                android:layout_height="match_parent"
                android:layout_gravity="end"
                app:layout="@layout/fragment_navigation_drawer"
                tools:layout="@layout/fragment_navigation_drawer" />
    
        </android.support.v4.widget.DrawerLayout>
    
    </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多