Android 側劃,如斯優雅 SwipePanel(側劃控件)

SwipePanel(側劃控件)

Background

對市面上實現的側劃返回不是很滿意(仿微信,QQ 通過修改窗口透明坑太多),最終決定還是親手寫一個高實用性的吧,效果如下所示,換個圖標,更多划動功能可以由你自己解鎖,總共一個 600 多行代碼的類,推薦通過閱讀源碼,你肯定會收穫很多哈。

Preview

Download

源碼地址:SwipePanel,喜歡的記得給個小星星哈。

Gradle:

implementation 'com.blankj:swipe-panel:1.0'

How to use

動態

final SwipePanel swipePanel = new SwipePanel(this);
swipePanel.setLeftEdgeSize(SizeUtils.dp2px(100));// 設置左側觸發閾值 100dp
swipePanel.setLeftDrawable(R.drawable.base_back);// 設置左側 icon
swipePanel.wrapView(findViewById(R.id.rootLayout));// 設置嵌套在 rootLayout 外層
swipePanel.setOnFullSwipeListener(new SwipePanel.OnFullSwipeListener() {// 設置完全劃開鬆手後的監聽
    @Override
    public void onFullSwipe(int direction) {
        finish();
        swipePanel.close(direction);// 關閉
    }
});

靜態

<com.blankj.swipepanel.SwipePanel
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/swipePanel"
        android:background="@color/mediumGray"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".LayoutSwipePanelActivity"
        app:isLeftCenter="false"
        app:leftEdgeSize="100dp"
        app:leftSwipeColor="@color/colorPrimary"
        app:leftDrawable="@drawable/base_back">

    ...

</com.blankj.swipepanel.SwipePanel>

API

方法名 屬性名 說明
setLeft(Top, Right, Bottom)SwipeColor app:left(top, right, bottom)SwipeColor 設置左(上、右、下)測顏色
setLeft(Top, Right, Bottom)EdgeSize app:left(top, right, bottom)EdgeSize 設置左(上、右、下)測觸發閾值
setLeft(Top, Right, Bottom)Drawable app:left(top, right, bottom)Drawable 設置左(上、右、下)測 icon
setLeft(Top, Right, Bottom)Center app:isLeft(Top, Right, Bottom)Center 設置左(上、右、下)測是否居中
setLeft(Top, Right, Bottom)Enabled app:isLeft(Top, Right, Bottom)Enabled 設置左(上、右、下)測是否可用
wrapView --- 設置嵌套在該 view 的外層
setOnFullSwipeListener --- 設置完全劃開鬆手後的監聽
isOpen --- 判斷是否被劃開
close --- 關閉

Change Log

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章