美文网首页
自定义Drawer,抽屉布局

自定义Drawer,抽屉布局

作者: ironman_ | 来源:发表于2017-07-01 01:10 被阅读0次

    主要内容:

    • 如何自定义Drawer的布局,比如在里面加一个ListView,以及一些需要注意到的点。

    有时候可以需要一个抽屉布局来显示和隐藏一些主菜单。

    在android studio里直接new -> Activity —> Navigation Drawer Activity。
    这时候就可以得到一个可以运行的drawer。

    修改拥有DrawerLayout的xml布局。

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.DrawerLayout xmlns:android="[http://schemas.android.com/apk/res/android](http://schemas.android.com/apk/res/android)"
        xmlns:app="[http://schemas.android.com/apk/res-auto](http://schemas.android.com/apk/res-auto)"
        xmlns:tools="[http://schemas.android.com/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_main2"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_gravity="start"
            android:fitsSystemWindows="true"
            >
    
            <include
                layout="@layout/nav_header_main2" />
    
            <android.support.v7.widget.RecyclerView
                android:id="@+id/drawer_RecyclerView"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
    
        </LinearLayout>
    
    </android.support.v4.widget.DrawerLayout>
    

    直接将原来的navigation节点(DrawerLayout的第二个节点)去掉。添加自己想要自定义的布局,这里是一个LinearLayout加上里面的布局。
    需要注意的是LinearLayout里要加上这两行:

    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    

    不然会有问题。

    todos:
    NaviationView是啥?有啥用?
    CoordinatorLayout有啥用?为啥google推他?

    相关文章

      网友评论

          本文标题:自定义Drawer,抽屉布局

          本文链接:https://www.haomeiwen.com/subject/arkwcxtx.html