使Android导航抽屉可滚动

时间:2017-04-25 07:53:33

标签: android android-navigation-drawer android-navigation android-navigationview

我有一个带有三个部分的导航抽屉,顶部,中部和底部我需要使中间部分可以滚动。

enter image description here

这是我目前的布局。

    <?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/navigation_drawer_container"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start">
<!-- begin Top Section--> 
        <android.support.design.widget.NavigationView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/background_black"
            android:paddingLeft="50dp"
            app:headerLayout="@layout/nav_header_main"
            />
<!--End Top Section-->    
<!-- begin Middle Section-->     
                    <android.support.design.widget.NavigationView
                        android:id="@+id/navigation_drawer_top"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:layout_gravity="top"
                        android:background="@color/menuColor"
                        android:paddingLeft="50dp"
                        app:itemTextAppearance="@style/NavigationDrawerStyle"
                        app:menu="@menu/menu_navigation_drawer_top"
                        app:itemTextColor="@color/menuTextColour" />
<!-- End Middle Section-->
<!-- begin Bottom Section-->         
        <android.support.design.widget.NavigationView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@color/background_black"
            app:headerLayout="@layout/nav_group_line"
            app:itemTextColor="@color/menuTextColour">

            <android.support.design.widget.NavigationView
                android:id="@+id/navigation_drawer_bottom"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:background="@color/menuColor_bottom"
                android:paddingLeft="50dp"
                app:itemTextAppearance="@style/NavigationDrawerStyle"
                app:itemTextColor="@color/menuTextColour"
                app:menu="@menu/menu_navigation_drawer_bottom" />
        </android.support.design.widget.NavigationView>
<!-- End Bottom Section-->      

    </android.support.design.widget.NavigationView>

如何在导航视图中使插入部分变得可见。

1 个答案:

答案 0 :(得分:1)

NavigationView为您提供了attr app:headerLayout,用于添加导航标题。 要添加页脚,只需在NavigationView中包含所需的页脚视图,

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    >

    <LinearLayout
        android:background="@android:color/darker_gray"
        android:clickable="true"
        android:id="@+id/ll_header"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical">

        <TextView
            android:gravity="center"
            android:id="@+id/nav_header_textview"
            android:layout_height="48dp"
            android:layout_width="match_parent"
            android:text="Your Header Text Here" />

    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:layout_below="@+id/ll_header"
        android:layout_above="@+id/ll_footer"
        android:id="@+id/navigation"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:menu="@menu/my_navigation_items" >


    </android.support.design.widget.NavigationView>

    <LinearLayout
        android:id="@+id/ll_footer"
        android:background="@android:color/darker_gray"
        android:layout_alignParentBottom="true"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical">

        <TextView
            android:gravity="center"
            android:id="@+id/nav_footer_textview"
            android:layout_height="48dp"
            android:layout_width="match_parent"
            android:text="Your Footer Text Here" />

    </LinearLayout>

</RelativeLayout>

例如,我使用了TextView。