Android 側劃,如斯優雅

Background

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

Preview

layout
back

Download

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

Gradle:git

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

相關文章
相關標籤/搜索