美文网首页
DrawerLayout+NavigationView侧滑栏的实

DrawerLayout+NavigationView侧滑栏的实

作者: 番茄tomato | 来源:发表于2020-01-07 16:07 被阅读0次

第一步 引入

    implementation'com.android.support:design:28.0.0'

第二步 创建layout文件

首先明确一点 我们新建一个activity后 通常都会有一个对应的layout文件
比如MainActivity对应的layout文件就是activity_main.xml
接下来要做的事情就非常简单了
activity_main.xml改名为include_main.xml
然后新建一个xml文件 名为activity_main

这个新的activity_main.xml内容如下:

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">
    
    <!--这里将原本的main布局通过include引用回来-->
    <include layout="@layout/include_main"/>

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <!--这里可以放置你想放置的任何东西 当成一个普通的布局文件即可-->


        </LinearLayout>
    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

相关文章

网友评论

      本文标题:DrawerLayout+NavigationView侧滑栏的实

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