开始使用
简单介绍
Android SwipeDrawer滑动抽屉库,可同时添加上下左右四个方向抽屉布局,抽屉打开模式有抽屉模式、覆盖模式、固定模式三种,支持无限嵌套,支持边缘滑动打开等,SwipeDrawer还可以当做下拉刷新布局使用,支持ListView、RecyclerView、GridView、ScrollView等。
如何使用
添加仓库地址:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
添加依赖:
dependencies {
...
implementation 'cn.Leaqi:SwipeDrawer:1.6'
}
在布局文件中加入:
<cn.leaqi.drawer.SwipeDrawer
android:layout_width="match_parent"
android:layout_height="match_parent"
app:leftLayout="@+id/leftDrawer">
<!-- leftLayout属性指定Left布局 -->
<LinearLayout
android:id="@+id/leftDrawer"
android:layout_width="200dp"
android:layout_height="match_parent"
android:background="#FF5722">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Left" />
</LinearLayout>
<!-- 默认第一个未指定ID的布局为主布局 -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Main" />
</RelativeLayout>
</cn.leaqi.drawer.SwipeDrawer>
使用文档
布局属性
| 属性名称 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| mode |
打开模式: :抽屉模式 :覆盖模式 :固定模式 |
enum | drawer |
| open |
初始化状态: :打开Left :打开Top :打开Right :打开Bottom |
enum | - |
| mask |
背景遮罩: :不开启 :固定遮罩颜色 :遮罩逐渐深浅 |
enum | none |
| mainLayout | 指定主布局ID | reference | 默认为第一个未指定ID的布局 |
| leftLayout | 指定Left布局ID | reference | - |
| topLayout | 指定Top布局ID | reference | - |
| rightLayout | 指定Right布局ID | reference | - |
| bottomLayout | 指定Bottom布局ID | reference | - |
| mainType |
主布局类型: :非滑动布局 :垂直滑动布局 :水平滑动布局 |
enum | view |
| leftType |
Left布局类型: :非滑动布局 :垂直滑动布局 :水平滑动布局 |
enum | view |
| topType |
Top布局类型: :非滑动布局 :垂直滑动布局 :水平滑动布局 |
enum | view |
| rightType |
Right布局类型: :非滑动布局 :垂直滑动布局 :水平滑动布局 |
enum | view |
| bottomType |
Bottom布局类型: :非滑动布局 :垂直滑动布局 :水平滑动布局 |
enum | view |
| leftMode |
指定Left打开模式: :抽屉模式 :覆盖模式 :固定模式 |
enum | drawer |
| topMode |
指定Top打开模式: :抽屉模式 :覆盖模式 :固定模式 |
enum | drawer |
| rightMode |
指定Right打开模式: :抽屉模式 :覆盖模式 :固定模式 |
enum | drawer |
| bottomMode |
指定Bottom打开模式: :抽屉模式 :覆盖模式 :固定模式 |
enum | drawer |
| mainOpen |
打开后主布局触摸事件: :不屏蔽 :只允许点击 :禁止所有触摸事件 |
enum | none |
| parentDrawer | 指定SwipeDrawer父布局ID,嵌套时使用 | reference | - |
| mainScroll | 指定主布局下滑动布局ID | reference | - |
| leftScroll | 指定Left主布局下滑动布局ID | reference | - |
| topScroll | 指定Top主布局下滑动布局ID | reference | - |
| rightScroll | 指定Right主布局下滑动布局ID | reference | - |
| bottomScroll | 指定Bottom布局下滑动布局ID | reference | - |
| leftDragOpen | Left布局拖拽打开 | boolean | true |
| topDragOpen | Top布局拖拽打开 | boolean | true |
| rightDragOpen | Right布局拖拽打开 | boolean | true |
| bottomDragOpen | Bottom布局拖拽打开 | boolean | true |
| showLayout | 非当前操作的布局是否隐藏 | boolean | false |
| autoClose | 打开后是否关闭其他SwipeDrawer | boolean | false |
| maskClose | 点击遮罩后关闭 | boolean | false |
| maskColor | 遮罩颜色 | color | #80000000 |
| dragClose | 允许拖拽关闭 | boolean | true |
| dragCloseType |
拖拽关闭类型: :全布局 :主布局 :抽屉布局 注:最低版本需 >= 1.4 |
enum | all |
| scrollOuterDrag | 滑动布局之外是否允许拖拽关闭 | boolean | false |
| autoLayout | 尺寸发生变化是否自动更新注:最低版本需 >= 1.2 | boolean | true |
| shrinkRange | 拖拽距离: 默认值为:,拖动方向高/宽度的5分之1 :可以拖拽,但不会开启或关闭 |
float | 5 |
| dragDamping | 拖拽阻力:0-9 :无阻力注:版本 >= 1.5 时值范围在0-99,值越大速度越快 |
int | 10 |
| dragRange | 边缘拖拽 布局方向的最边缘dip才允许拖拽 :全布局拖拽 |
dip | 0 |
| leftDragRange | Left边缘拖拽 Left布局方向的最边缘dip才允许拖拽 :全布局拖拽注:最低版本需 >= 1.5 |
dip | 0 |
| topDragRange | Top边缘拖拽 Top布局方向的最边缘dip才允许拖拽 :全布局拖拽注:最低版本需 >= 1.5 |
dip | 0 |
| rightDragRange | Right边缘拖拽 Right布局方向的最边缘dip才允许拖拽 :全布局拖拽注:最低版本需 >= 1.5 |
dip | 0 |
| bottomDragRange | Bottom边缘拖拽 Bottom布局方向的最边缘dip才允许拖拽 :全布局拖拽注:最低版本需 >= 1.5 |
dip | 0 |
| leftOffset | Left布局偏移 Left布局向外偏移dip注:最低版本需 >= 1.5 |
dip | 0 |
| topOffset | Top布局偏移 Top布局向外偏移dip注:最低版本需 >= 1.5 |
dip | 0 |
| rightOffset | Right布局偏移 Right布局向外偏移dip注:最低版本需 >= 1.5 |
dip | 0 |
| bottomOffset | Bottom布局偏移 Bottom布局向外偏移dip注:最低版本需 >= 1.5 |
dip | 0 |
| dragSlop | 拖拽拦截距离 当拖拽距离大于时才拦截事件注:最低版本需 >= 1.1 |
dip | 5px |
| turnCancel | 回拽取消操作 当拖拽达到打开或关闭距离时,回拽距离大于时释放后会取消操作注:最低版本需 >= 1.6 |
dip | 10px |
| maxDragSize | 最大拖拽高/宽度 :布局高/宽度 |
dip | 0 |
| duration | 动画速度 | int | 200 |
| interpolator | 动画插值器 | reference | AccelerateDecelerateInterpolator |
获取属性
| 方法名称 | 说明 | 返回 |
|---|---|---|
| getShow() |
获取是否打开 |
boolean |
| getIntercept() |
获取是否拦截事件,及正在拖拽 |
boolean |
| getArriveRange() |
获取拖拽是否超过打开/关闭的距离 |
boolean |
| getDirection() |
获取操作的方向: :未操作 :Left布局 :Top布局 :Right布局 :Bottom布局 |
int |
| getMaskView() |
获取遮罩View,未设置为 |
view |
| getMainView() |
获取主布局View,未设置为 |
view |
| getLeftView() |
获取Left布局View,未设置为 |
view |
| getTopView() |
获取Top布局View,未设置为 |
view |
| getRightView() |
获取Right布局View,未设置为 |
view |
| getBottomView() |
获取Bottom布局View,未设置为 |
view |
| getMode() |
获取属性: :抽屉模式 :覆盖模式 :固定模式 |
int |
| getLeftMode() |
获取属性: :抽屉模式 :覆盖模式 :固定模式 |
int |
| getTopMode() |
获取属性: :抽屉模式 :覆盖模式 :固定模式 |
int |
| getRightMode() |
获取属性: :抽屉模式 :覆盖模式 :固定模式 |
int |
| getBottomMode() |
获取属性: :抽屉模式 :覆盖模式 :固定模式 |
int |
| getMask() |
获取属性: :不开启 :固定遮罩颜色 :遮罩逐渐深浅 |
int |
| getMainType() |
获取属性: :非滑动布局 :垂直滑动布局 :水平滑动布局 |
int |
| getLeftType() |
获取属性: :非滑动布局 :垂直滑动布局 :水平滑动布局 |
int |
| getTopType() |
获取属性: :非滑动布局 :垂直滑动布局 :水平滑动布局 |
int |
| getRightType() |
获取属性: :非滑动布局 :垂直滑动布局 :水平滑动布局 |
int |
| getBottomType() |
获取属性: :非滑动布局 :垂直滑动布局 :水平滑动布局 |
int |
| getMainOpen() |
获取属性: :不屏蔽 :只允许点击 :禁止所有触摸事件 |
int |
| getShrinkRange() |
获取属性 |
float |
| getDragDamping() |
获取属性 |
int |
| getDragRange() |
获取属性 |
int |
| getLeftDragRange() |
获取属性注:最低版本需 >= 1.5 |
int |
| getTopDragRange() |
获取属性注:最低版本需 >= 1.5 |
int |
| getRightDragRange() |
获取属性注:最低版本需 >= 1.5 |
int |
| getBottomDragRange() |
获取属性注:最低版本需 >= 1.5 |
int |
| getLeftOffset() |
获取属性注:最低版本需 >= 1.5 |
int |
| getTopOffset() |
获取属性注:最低版本需 >= 1.5 |
int |
| getRightOffset() |
获取属性注:最低版本需 >= 1.5 |
int |
| getBottomOffset() |
获取属性注:最低版本需 >= 1.5 |
int |
| getDragSlop() |
获取属性注:最低版本需 >= 1.1 |
int |
| getTurnCancel() |
获取属性注:最低版本需 >= 1.6 |
int |
| getMaxDragSize() |
获取属性 |
int |
| getDuration() |
获取属性 |
int |
| getLeftDragOpen() |
获取属性 |
boolean |
| getTopDragOpen() |
获取属性 |
boolean |
| getRightDragOpen() |
获取属性 |
boolean |
| getBottomDragOpen() |
获取属性 |
boolean |
| getShowLayout() |
获取属性 |
boolean |
| getAutoClose() |
获取属性 |
boolean |
| getMaskClose() |
获取属性 |
boolean |
| getMaskColor() |
获取属性 |
int |
| getScrollOuterDrag() |
获取属性 |
boolean |
| getAutoLayout() |
获取属性注:最低版本需 >= 1.4 |
boolean |
设置属性
| 方法名称 | 说明 | 参数 |
|---|---|---|
| setMainScale(float scale) |
设置主布局缩放 |
scale: |
| setMainRotation(float rotation) |
设置主布局旋转 |
rotation: |
| setIntercept(boolean intercept) |
设置手动拦截所有方向触摸事件 |
intercept: |
| setIntercept(View view, boolean intercept) |
设置手动拦截指定方向触摸事件 |
view: intercept: |
| setIntercept(int type, boolean intercept) |
设置手动拦截指定方向触摸事件 |
type: :Left方向 :Top方向 :Right方向 :Bottom方向 intercept: |
| setMode(int type) |
设置属性 |
type: :抽屉模式 :覆盖模式 :固定模式 |
| setLeftMode(int type) |
设置属性 |
type: :抽屉模式 :覆盖模式 :固定模式 |
| setRightMode(int type) |
设置属性 |
type: :抽屉模式 :覆盖模式 :固定模式 |
| setTopMode(int type) |
设置属性 |
type: :抽屉模式 :覆盖模式 :固定模式 |
| setBottomMode(int type) |
设置属性 |
type: :抽屉模式 :覆盖模式 :固定模式 |
| setMask(int type) |
设置属性 |
type: :不开启 :固定遮罩颜色 :遮罩逐渐深浅 |
| setMainType(int type) |
设置属性 |
type: :非滑动布局 :垂直滑动布局 :水平滑动布局 |
| setLeftType(int type) |
设置属性 |
type: :非滑动布局 :垂直滑动布局 :水平滑动布局 |
| setTopType(int type) |
设置属性 |
type: :非滑动布局 :垂直滑动布局 :水平滑动布局 |
| setRightType(int type) |
设置属性 |
type: :非滑动布局 :垂直滑动布局 :水平滑动布局 |
| setBottomType(int type) |
设置属性 |
type: :非滑动布局 :垂直滑动布局 :水平滑动布局 |
| setMainOpen(int type) |
设置属性 |
type: :不屏蔽 :只允许点击 :禁止所有触摸事件 |
| setMainLayout(int id) |
设置属性 |
id: |
| setMainLayout(View view) |
设置属性 |
view: |
| setLeftLayout(int id) |
设置属性 |
id: |
| setLeftLayout(View view) |
设置属性 |
view: |
| setTopLayout(int id) |
设置属性 |
id: |
| setTopLayout(View view) |
设置属性 |
view: |
| setRightLayout(int id) |
设置属性 |
id: |
| setRightLayout(View view) |
设置属性 |
view: |
| setBottomLayout(int id) |
设置属性 |
id: |
| setBottomLayout(View view) |
设置属性 |
view: |
| setMainScroll(int id) |
设置属性 |
id: |
| setMainScroll(View view) |
设置属性 |
view: |
| setLeftScroll(int id) |
设置属性 |
id: |
| setLeftScroll(View view) |
设置属性 |
view: |
| setTopScroll(int id) |
设置属性 |
id: |
| setTopScroll(View view) |
设置属性 |
view: |
| setRightScroll(int id) |
设置属性 |
id: |
| setRightScroll(View view) |
设置属性 |
view: |
| setBottomScroll(int id) |
设置属性 |
id: |
| setBottomScroll(View view) |
设置属性 |
view: |
| setParentDrawer(int id) |
设置属性 |
id: |
| setParentDrawer(SwipeDrawer view) |
设置属性 |
SwipeDrawer: |
| setShrinkRange(float num) |
设置属性 |
num: |
| setDragDamping(int num) |
设置属性 |
num:0-9 |
| setDragRange(int num) |
设置属性 |
num:px |
| setLeftDragRange(int num) |
设置属性注:最低版本需 >= 1.5 |
num:px |
| setTopDragRange(int num) |
设置属性注:最低版本需 >= 1.5 |
num:px |
| setRightDragRange(int num) |
设置属性注:最低版本需 >= 1.5 |
num:px |
| setBottomDragRange(int num) |
设置属性注:最低版本需 >= 1.5 |
num:px |
| setLeftOffset(int num) |
设置属性注:最低版本需 >= 1.5 |
num:px |
| setTopOffset(int num) |
设置属性注:最低版本需 >= 1.5 |
num:px |
| setRightOffset(int num) |
设置属性注:最低版本需 >= 1.5 |
num:px |
| setBottomOffset(int num) |
设置属性注:最低版本需 >= 1.5 |
num:px |
| setDragSlop(int num) |
设置属性注:最低版本需 >= 1.1 |
num:px |
| setTurnCancel(int num) |
设置属性注:最低版本需 >= 1.6 |
num:px |
| setMaxDragSize(int num) |
设置属性 |
num:px |
| setLeftDragOpen(boolean bool) |
设置属性 |
bool: |
| setTopDragOpen(boolean bool) |
设置属性 |
bool: |
| setRightDragOpen(boolean bool) |
设置属性 |
bool: |
| setBottomDragOpen(boolean bool) |
设置属性 |
bool: |
| setShowLayout(boolean bool) |
设置属性 |
bool: |
| setAutoClose(boolean bool) |
设置属性 |
bool: |
| setMaskClose(boolean bool) |
设置属性 |
bool: |
| setMaskColor(int color) |
设置属性 |
int: |
| setDragClose(boolean bool) |
设置属性 |
bool: |
| setScrollOuterDrag(boolean bool) |
设置属性 |
bool: |
| setAutoLayout(boolean bool) |
设置属性注:最低版本需 >= 1.4 |
bool: |
| setDuration(int ms) |
设置属性 |
ms:毫秒 |
| setInterpolator(Interpolator interpolator) |
设置属性 |
interpolator:插值器 |
回调接口
| 方法名称 | 说明 | 参数 |
|---|---|---|
| setOnDrawerState(OnDrawerState listener) |
监听开始、移动、开启、关闭、取消回调 |
listener: |
| setOnDrawerSwitch(OnDrawerSwitch listener) |
监听开启、关闭回调 |
listener: |
| setOnDrawerChange(OnDrawerChange listener) |
监听改变,由参数返回各种状态 |
listener: |
调用方法
| 方法名称 | 说明 | 参数 |
|---|---|---|
| openDrawer(int type) |
打开指定方向 |
type: :Left方向 :Top方向 :Right方向 :Bottom方向 |
| openDrawer(int type, boolean anim) |
打开指定方向、动画设置 |
type: :Left方向 :Top方向 :Right方向 :Bottom方向 anim:是否开启动画 |
| openDrawer(int type, boolean anim, boolean call) |
打开指定方向、动画设置、回调设置 |
type: :Left方向 :Top方向 :Right方向 :Bottom方向 anim:是否开启动画 call:是否回调接口 |
| closeDrawer() |
关闭 |
- |
| closeDrawer(boolean anim) |
关闭、动画设置 |
anim:是否开启动画 |
| closeDrawer(boolean anim, boolean call) |
关闭、动画设置、回调设置 |
anim:是否开启动画 call:是否回调接口 |
| closeDrawer(int type) |
关闭指定方向 |
type: :Left方向 :Top方向 :Right方向 :Bottom方向 |
| closeDrawer(int type, boolean anim) |
关闭指定方向、动画设置 |
type: :Left方向 :Top方向 :Right方向 :Bottom方向 anim:是否开启动画 |
| closeDrawer(int type, boolean anim, boolean call) |
关闭指定方向、动画设置、回调设置 |
type: :Left方向 :Top方向 :Right方向 :Bottom方向 anim:是否开启动画 call:是否回调接口 |
| toggleDrawer(int type) |
打开/关闭指定方向 |
type: :Left方向 :Top方向 :Right方向 :Bottom方向 |
| toggleDrawer(int type, boolean anim) |
打开/关闭指定方向、动画设置 |
type: :Left方向 :Top方向 :Right方向 :Bottom方向 anim:是否开启动画 |
| toggleDrawer(int type, boolean anim, boolean call) |
打开/关闭指定方向、动画设置、回调设置 |
type: :Left方向 :Top方向 :Right方向 :Bottom方向 anim:是否开启动画 call:是否回调接口 |
| setIntercept(boolean intercept) |
屏蔽所有方向触摸事件 |
intercept:是否允许触摸 |
| setIntercept(int type, boolean intercept) |
屏蔽指定方向触摸事件 |
type: :Left方向 :Top方向 :Right方向 :Bottom方向 intercept:是否允许触摸 |
| setIntercept(View view, boolean intercept) |
屏蔽指定方向触摸事件 |
view:指定方向 intercept:是否允许触摸 |
| drawerLayout() |
手动更新布局,需在关闭的情况下进行注:最低版本需 >= 1.2 |
- |
全局方法
| 方法名称 | 说明 | 参数/返回 |
|---|---|---|
| SwipeDrawer.setAllIntercept(boolean bool) |
设置屏蔽所有触摸事件 |
bool: |
| SwipeDrawer.getAllIntercept() |
获取触摸事件是否屏蔽 |
boolean |
| SwipeDrawer.getParentDrawer(View view) |
获取view的父级 |
SwipeDrawer |