Start using
Introduce
Android SwipeDrawer sliding drawer library can add up, down, left and right drawer layouts at the same time. There are three drawer opening modes: drawer mode, overlay mode and fixed mode. It supports unlimited nesting and edge sliding opening. Swipedrawer can also be used as a drop-down refresh layout, and supports listview, recyclerview, GridView, Scrollview, etc.
Setup
Addrepositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Adddependencies:
dependencies {
...
implementation 'cn.Leaqi:SwipeDrawer:1.6'
}
Addto the layout file:
<cn.leaqi.drawer.SwipeDrawer
android:layout_width="match_parent"
android:layout_height="match_parent"
app:leftLayout="@+id/leftDrawer">
<!-- The leftLayout property specifies the left layout -->
<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>
<!-- By default, the first layout without ID is the main layout -->
<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>
Using docs
Layout attribute
Attribute name | explain | type | Default value |
---|---|---|---|
mode |
Open mode: : Drawer mode : Cover mode : Fixed mode |
enum | drawer |
open |
Initialization status: : Open left : Open top : Open right : Open bottom |
enum | - |
mask |
Background mask: : Not used : Fixed color : Gradual depth |
enum | none |
mainLayout | Specifies the main layout ID | reference | The default is the first layout with no ID specified |
leftLayout | Specifies the left layout ID | reference | - |
topLayout | Specifies the top layout ID | reference | - |
rightLayout | Specifies the right layout ID | reference | - |
bottomLayout | Specifies the bottom layout ID | reference | - |
mainType |
Main layout type: : Non sliding layout : Vertical sliding layout : Horizontal sliding layout |
enum | view |
leftType |
Left layout type: : Non sliding layout : Vertical sliding layout : Horizontal sliding layout |
enum | view |
topType |
Top layout type: : Non sliding layout : Vertical sliding layout : Horizontal sliding layout |
enum | view |
rightType |
Right layout type: : Non sliding layout : Vertical sliding layout : Horizontal sliding layout |
enum | view |
bottomType |
Bottom layout type: : Non sliding layout : Vertical sliding layout : Horizontal sliding layout |
enum | view |
leftMode |
Specify left on mode: : Drawer mode : Cover mode : Fixed mode |
enum | drawer |
topMode |
Specify top on mode: : Drawer mode : Cover mode : Fixed mode |
enum | drawer |
rightMode |
Specify right on mode: : Drawer mode : Cover mode : Fixed mode |
enum | drawer |
bottomMode |
Specify bottom on mode: : Drawer mode : Cover mode : Fixed mode |
enum | drawer |
mainOpen |
Main layout touch event after opening: : Unshielded : Click only : Disable all touch events |
enum | none |
parentDrawer | Specifies the SwipeDrawer parent layout ID, which is used when nesting | reference | - |
mainScroll | Specifies the sliding layout ID under the main layout | reference | - |
leftScroll | Specifies the sliding layout ID under the left layout | reference | - |
topScroll | Specifies the sliding layout ID under the top layout | reference | - |
rightScroll | Specifies the sliding layout ID under the right layout | reference | - |
bottomScroll | Specifies the sliding layout ID under the bottom layout | reference | - |
leftDragOpen | Left layout drag open | boolean | true |
topDragOpen | Top layout drag open | boolean | true |
rightDragOpen | Right layout drag open | boolean | true |
bottomDragOpen | Bottom layout drag open | boolean | true |
showLayout | Whether the layout of non current operation is hidden | boolean | false |
autoClose | Close other SwipeDrawer after opening | boolean | false |
maskClose | Click mask to close | boolean | false |
maskColor | Mask color | color | #80000000 |
dragClose | Allow drag close | boolean | true |
dragCloseType |
Drag Close Type: :Whole Layout :Main Layout :Drawer Layout Warn:Minimum version required >= 1.4 |
enum | all |
scrollOuterDrag | Whether dragging is allowed outside the sliding layout | boolean | false |
autoLayout | Whether to update automatically when the size changesWarn:Minimum version required >= 1.2 | boolean | true |
shrinkRange | Drag distance: Default value: , Drag direction 1 / 5 of height / width : Can drag, But it will not turn on or off |
float | 5 |
dragDamping | Drag damping: 0-9 : No dampingWarn:When version >= 1.5, the value range is 0-99, the larger the value, the faster the speed |
int | 10 |
dragRange | Edge drag Only dip at the most edge of the layout direction can be dragged : Full layout drag |
dip | 0 |
leftDragRange | Left edge drag Left Only dip at the most edge of the layout direction can be dragged : Full layout dragWarn:Minimum version required >= 1.5 |
dip | 0 |
topDragRange | Top edge drag Top Only dip at the most edge of the layout direction can be dragged : Full layout dragWarn:Minimum version required >= 1.5 |
dip | 0 |
rightDragRange | Right edge drag Right Only dip at the most edge of the layout direction can be dragged : Full layout dragWarn:Minimum version required >= 1.5 |
dip | 0 |
bottomDragRange | Bottom edge drag Bottom Only dip at the most edge of the layout direction can be dragged : Full layout dragWarn:Minimum version required >= 1.5 |
dip | 0 |
leftOffset | Left layout offset Left layout offset outwarddipWarn:Minimum version required >= 1.5 |
dip | 0 |
topOffset | Top layout offset Top layout offset outwarddipWarn:Minimum version required >= 1.5 |
dip | 0 |
rightOffset | Right layout offset Right layout offset outwarddipWarn:Minimum version required >= 1.5 |
dip | 0 |
bottomOffset | Bottom layout offset Bottom layout offset outwarddipWarn:Minimum version required >= 1.5 |
dip | 0 |
dragSlop | Drag intercept distance The event is intercepted only when the drag distance is greater thanWarn:Minimum version required >= 1.1 |
dip | 5px |
turnCancel | Pull back to cancel operation When the drag reaches the open or closed distance, the operation will be canceled after releasing when the drag back distance is greater than Warn:Minimum version required >= 1.6 |
dip | 10px |
maxDragSize | Maximum drag height / width : Layout height / width |
dip | 0 |
duration | Animation speed | int | 200 |
interpolator | Animation interpolator | reference | AccelerateDecelerateInterpolator |
Get attribute
Method name | explain | return |
---|---|---|
getShow() |
Get whether to open |
boolean |
getIntercept() |
Get whether the event is intercepted and whether it is being dragged |
boolean |
getArriveRange() |
Gets whether the drag exceeds the open / close distance |
boolean |
getDirection() |
Gets the direction of the operation: : Not operated : Left layout : Top layout : Right layout : Bottom layout |
int |
getMaskView() |
Get mask view, not set to |
view |
getMainView() |
Get main layout view, not set to |
view |
getLeftView() |
Get left layout view, not set to |
view |
getTopView() |
Get top layout view, not set to |
view |
getRightView() |
Get right layout view, not set to |
view |
getBottomView() |
Get bottom layout view, not set to |
view |
getMode() |
Getattribute: : Drawer mode : Cover mode : Fixed mode |
int |
getLeftMode() |
Getattribute: : Drawer mode : Cover mode : Fixed mode |
int |
getTopMode() |
Getattribute: : Drawer mode : Cover mode : Fixed mode |
int |
getRightMode() |
Getattribute: : Drawer mode : Cover mode : Fixed mode |
int |
getBottomMode() |
Getattribute: : Drawer mode : Cover mode : Fixed mode |
int |
getMask() |
Getattribute: : Not open : Fixed color : Gradual depth |
int |
getMainType() |
Getattribute: : Non sliding layout : Vertical sliding layout : Horizontal sliding layout |
int |
getLeftType() |
Getattribute: : Non sliding layout : Vertical sliding layout : Horizontal sliding layout |
int |
getTopType() |
Getattribute: : Non sliding layout : Vertical sliding layout : Horizontal sliding layout |
int |
getRightType() |
Getattribute: : Non sliding layout : Vertical sliding layout : Horizontal sliding layout |
int |
getBottomType() |
Getattribute: : Non sliding layout : Vertical sliding layout : Horizontal sliding layout |
int |
getMainOpen() |
Getattribute: : Unshielded : Click only : Disable all touch events |
int |
getShrinkRange() |
Getattribute |
float |
getDragDamping() |
Getattribute |
int |
getDragRange() |
Getattribute |
int |
getLeftDragRange() |
GetattributeWarn:Minimum version required >= 1.5 |
int |
getTopDragRange() |
GetattributeWarn:Minimum version required >= 1.5 |
int |
getRightDragRange() |
GetattributeWarn:Minimum version required >= 1.5 |
int |
getBottomDragRange() |
GetattributeWarn:Minimum version required >= 1.5 |
int |
getLeftOffset() |
GetattributeWarn:Minimum version required >= 1.5 |
int |
getTopOffset() |
GetattributeWarn:Minimum version required >= 1.5 |
int |
getRightOffset() |
GetattributeWarn:Minimum version required >= 1.5 |
int |
getBottomOffset() |
GetattributeWarn:Minimum version required >= 1.5 |
int |
getDragSlop() |
GetattributeWarn:Minimum version required >= 1.1 |
int |
getTurnCancel() |
GetattributeWarn:Minimum version required >= 1.6 |
int |
getMaxDragSize() |
Getattribute |
int |
getDuration() |
Getattribute |
int |
getLeftDragOpen() |
Getattribute |
boolean |
getTopDragOpen() |
Getattribute |
boolean |
getRightDragOpen() |
Getattribute |
boolean |
getBottomDragOpen() |
Getattribute |
boolean |
getShowLayout() |
Getattribute |
boolean |
getAutoClose() |
Getattribute |
boolean |
getMaskClose() |
Getattribute |
boolean |
getMaskColor() |
Getattribute |
int |
getScrollOuterDrag() |
Getattribute |
boolean |
getAutoLayout() |
GetattributeWarn:Minimum version required >= 1.4 |
boolean |
Set attribute
Method name | explain | parameter |
---|---|---|
setMainScale(float scale) |
Set main layout scale |
scale: |
setMainRotation(float rotation) |
Set mani layout rotation |
rotation: |
setIntercept(boolean intercept) |
Set manual interception of all directional touch events |
intercept: |
setIntercept(View view, boolean intercept) |
Set manual interception of all directional touch events |
view: intercept: |
setIntercept(int type, boolean intercept) |
Set manual interception of all directional touch events |
type: : Left direction : Top direction : Right direction : Bottom direction intercept: |
setMode(int type) |
Setattribute |
type: : Drawer mode : Cover mode : Fixed mode |
setLeftMode(int type) |
Setattribute |
type: : Drawer mode : Cover mode : Fixed mode |
setRightMode(int type) |
Setattribute |
type: : Drawer mode : Cover mode : Fixed mode |
setTopMode(int type) |
Setattribute |
type: : Drawer mode : Cover mode : Fixed mode |
setBottomMode(int type) |
Setattribute |
type: : Drawer mode : Cover mode : Fixed mode |
setMask(int type) |
Setattribute |
type: : Not open : Fixed color : Gradual depth |
setMainType(int type) |
Setattribute |
type: : Non sliding layout : Vertical sliding layout : Horizontal sliding layout |
setLeftType(int type) |
Setattribute |
type: : Non sliding layout : Vertical sliding layout : Horizontal sliding layout |
setTopType(int type) |
Setattribute |
type: : Non sliding layout : Vertical sliding layout : Horizontal sliding layout |
setRightType(int type) |
Setattribute |
type: : Non sliding layout : Vertical sliding layout : Horizontal sliding layout |
setBottomType(int type) |
Setattribute |
type: : Non sliding layout : Vertical sliding layout : Horizontal sliding layout |
setMainOpen(int type) |
Setattribute |
type: : Unshielded : Click only : Disable all touch events |
setMainLayout(int id) |
Setattribute |
id: |
setMainLayout(View view) |
Setattribute |
view: |
setLeftLayout(int id) |
Setattribute |
id: |
setLeftLayout(View view) |
Setattribute |
view: |
setTopLayout(int id) |
Setattribute |
id: |
setTopLayout(View view) |
Setattribute |
view: |
setRightLayout(int id) |
Setattribute |
id: |
setRightLayout(View view) |
Setattribute |
view: |
setBottomLayout(int id) |
Setattribute |
id: |
setBottomLayout(View view) |
Setattribute |
view: |
setMainScroll(int id) |
Setattribute |
id: |
setMainScroll(View view) |
Setattribute |
view: |
setLeftScroll(int id) |
Setattribute |
id: |
setLeftScroll(View view) |
Setattribute |
view: |
setTopScroll(int id) |
Setattribute |
id: |
setTopScroll(View view) |
Setattribute |
view: |
setRightScroll(int id) |
Setattribute |
id: |
setRightScroll(View view) |
Setattribute |
view: |
setBottomScroll(int id) |
Setattribute |
id: |
setBottomScroll(View view) |
Setattribute |
view: |
setParentDrawer(int id) |
Setattribute |
id: |
setParentDrawer(SwipeDrawer view) |
Setattribute |
SwipeDrawer: |
setShrinkRange(float num) |
Setattribute |
num: |
setDragDamping(int num) |
Setattribute |
num: 0-9 |
setDragRange(int num) |
Setattribute |
num: px |
setLeftDragRange(int num) |
SetattributeWarn:Minimum version required >= 1.5 |
num: px |
setTopDragRange(int num) |
SetattributeWarn:Minimum version required >= 1.5 |
num: px |
setRightDragRange(int num) |
SetattributeWarn:Minimum version required >= 1.5 |
num: px |
setBottomDragRange(int num) |
SetattributeWarn:Minimum version required >= 1.5 |
num: px |
setLeftOffset(int num) |
SetattributeWarn:Minimum version required >= 1.5 |
num:px |
setTopOffset(int num) |
SetattributeWarn:Minimum version required >= 1.5 |
num:px |
setRightOffset(int num) |
SetattributeWarn:Minimum version required >= 1.5 |
num:px |
setBottomOffset(int num) |
SetattributeWarn:Minimum version required >= 1.5 |
num:px |
setDragSlop(int num) |
SetattributeWarn:Minimum version required >= 1.1 |
num:px |
setTurnCancel(int num) |
SetattributeWarn:Minimum version required >= 1.6 |
num:px |
setMaxDragSize(int num) |
Setattribute |
num: px |
setLeftDragOpen(boolean bool) |
Setattribute |
bool: |
setTopDragOpen(boolean bool) |
Setattribute |
bool: |
setRightDragOpen(boolean bool) |
Setattribute |
bool: |
setBottomDragOpen(boolean bool) |
Setattribute |
bool: |
setShowLayout(boolean bool) |
Setattribute |
bool: |
setAutoClose(boolean bool) |
Setattribute |
bool: |
setMaskClose(boolean bool) |
Setattribute |
bool: |
setMaskColor(int color) |
Setattribute |
int: |
setDragClose(boolean bool) |
Setattribute |
bool: |
setScrollOuterDrag(boolean bool) |
Setattribute |
bool: |
setAutoLayout(boolean bool) |
SetattributeWarn:Minimum version required >= 1.4 |
bool: |
setDuration(int ms) |
Setattribute |
ms: ms |
setInterpolator(Interpolator interpolator) |
Setattribute |
interpolator: |
Call Interface
Method name | explain | parameter |
---|---|---|
setOnDrawerState(OnDrawerState listener) |
Listening start, move, start, close and cancel callback |
listener: |
setOnDrawerSwitch(OnDrawerSwitch listener) |
Listening on / off callback |
listener: |
setOnDrawerChange(OnDrawerChange listener) |
Monitor changes and return various statuses by parameters |
listener: |
Call method
Method name | explain | parameter |
---|---|---|
openDrawer(int type) |
Open the specified direction |
type: : Left direction : Top direction : Right direction : Bottom direction |
openDrawer(int type, boolean anim) |
Open the specified direction、 Animation settings |
type: : Left direction : Top direction : Right direction : Bottom direction anim: Turn on animation |
openDrawer(int type, boolean anim, boolean call) |
Open the specified direction、 Animation settings、 Callback settings |
type: : Left direction : Top direction : Right direction : Bottom direction anim: Turn on animation call: Callback interface |
closeDrawer() |
close |
- |
closeDrawer(boolean anim) |
Close, animation |
anim: Turn on animation |
closeDrawer(boolean anim, boolean call) |
Close、 Animation settings、 callback settings |
anim: Turn on animation call: Callback interface |
closeDrawer(int type) |
Turn off the specified direction |
type: : Left direction : Top direction : Right direction : Bottom direction |
closeDrawer(int type, boolean anim) |
Turn off the specified direction、 Animation settings |
type: : Left direction : Top direction : Right direction : Bottom direction anim: Turn on animation |
closeDrawer(int type, boolean anim, boolean call) |
Turn off the specified direction、 Animation settings、 callback settings |
type: : Left direction : Top direction : Right direction : Bottom direction anim: Turn on animation call: Callback interface |
toggleDrawer(int type) |
Turns the specified direction on / off |
type: : Left direction : Top direction : Right direction : Bottom direction |
toggleDrawer(int type, boolean anim) |
Turns the specified direction on / off、 Animation settings |
type: : Left direction : Top direction : Right direction : Bottom direction anim: Turn on animation |
toggleDrawer(int type, boolean anim, boolean call) |
Turns the specified direction on / off、 Animation settings、 callback settings |
type: : Left direction : Top direction : Right direction : Bottom direction anim: Turn on animation call: Callback interface |
setIntercept(boolean intercept) |
Shield touch events in all directions |
intercept:Whether touch is allowed |
setIntercept(int type, boolean intercept) |
Shield the touch event in the specified direction |
type: :Left direction :Top direction :Right direction :Bottom direction intercept:Whether touch is allowed |
setIntercept(View view, boolean intercept) |
Shield the touch event in the specified direction |
view:Specify direction intercept:Whether touch is allowed |
drawerLayout() |
Update Layout Manually,It needs to be done whenis closedWarn:Minimum version required >= 1.2 |
- |
Static method
Method name | explain | Parameter / return |
---|---|---|
SwipeDrawer.setAllIntercept(boolean bool) |
Set to mask all touch events |
bool: |
SwipeDrawer.getAllIntercept() |
Get whether touch event is shielded |
boolean |
SwipeDrawer.getParentDrawer(View view) |
Get the parent of view |
SwipeDrawer |