目录
添加依赖
DrawerLayout存在于v4包中,我们只需要在xml配置即可
最新的v7是包含v4,直接依赖v7即可,注意androidx的包名变化。
implementation 'com.android.support:appcompat-v7:28.0.3'
布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/holo_red_dark"/>
<RelativeLayout android:layout_gravity="end" android:fitsSystemWindows="true" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/holo_green_dark"/>
<RelativeLayout android:layout_gravity="start" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/holo_blue_bright"/>
</android.support.v4.widget.DrawerLayout>
DrawerLayout 的直接子布局layout_gravity属性指定了子布局的位置
有start、center、end,分别表示左中右的位置,不指定默认为center。
冲突处理
通过setDrawerLockMode方法锁定与解锁DrawerLayout
踩坑
1.DrawerLayout不能滑动关闭的解决办法
https://blog.csdn.net/noobzsb/article/details/70597764
左侧布局要放到所有布局的最后
0 条评论