DrawerLayout顾名思义就是一个管理布局的。使用方式可以与其它的布局类类似。
DrawerLayout带有滑动的功能。只要按照drawerLayout的规定布局方式写完布局,就能有侧滑的效果。
直接将DrawerLayout作为根布局,然后其内部第一个View为内容区域
第二个View为左侧菜单
第三个View为右侧侧滑菜单
当前第三个是可选的。
注意这个属性android:layout_gravity="start"里面左中右分别放三个layout就可以了,简单的说在最外层套一个Drawerlayout,然后左中右分别可设置三个布局了,当然记得加上layout_gravity属性,同时中间布局是不可滑动的,左右两边可以,当然你也可以只设置一边
?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" tools:context="com.example.administrator.layout.avitivty.tableActivity" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="start" android:background="@color/colorAccent" android:orientation="vertical" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <android.support.design.widget.TabLayout android:id="@+id/Tab_content" android:layout_height="0dp" android:layout_width="match_parent" android:layout_weight="1" /> <android.support.v4.view.ViewPager android:id="@+id/pager_content" android:layout_height="0dp" android:layout_width="match_parent" android:layout_weight="8" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="right" android:background="@color/colorPrimaryDark" android:orientation="vertical" /> </android.support.v4.widget.DrawerLayout>