RecyclerView版的swip 菜單:SwipeMenuRecyclerView

jopen 8年前發布 | 67K 次閱讀 Android開發 移動開發

RecyclerView版的swip 菜單。

使用說明:

添加依賴

dependencies {
    compile 'com.tubb.smrv:swipemenu-recyclerview:3.0.2'
}

第一步

使用SwipeMenuLayout來把item的內容視圖和swipe菜單視圖組合在一起

<?xml version="1.0" encoding="utf-8"?>
<com.tubb.smrv.SwipeMenuLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <!-- item content view, the id must be (smContentView) -->
    <include android:id="@id/smContentView" layout="@layout/item_simple_content"/>
    <!-- item swipe menu, the id must be (smMenuView) -->
    <include android:id="@id/smMenuView" layout="@layout/item_simple_menu"/>
</com.tubb.smrv.SwipeMenuLayout>

第二步

使用我們自定義的RecyclerView

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}"
    android:id="@+id/swipeRefreshLayout">

    <com.tubb.smrv.SwipeMenuRecyclerView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</android.support.v4.widget.SwipeRefreshLayout>

更多的細節請查看demo項目。

自定義

你可以開啟和關閉swipe功能,在onBindViewHolder方法中設置pen/close Interpolator 。

itemView.setSwipeEnable(swipeEnable);
itemView.setOpenInterpolator(mRecyclerView.getOpenInterpolator());
itemView.setCloseInterpolator(mRecyclerView.getCloseInterpolator());

 anim_duration屬性設置swipe動畫的時間,默認是500ms。

<?xml version="1.0" encoding="utf-8"?>
<com.tubb.smrv.SwipeMenuLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:swipemenu="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    swipemenu:anim_duration="300">

</com.tubb.smrv.SwipeMenuLayout>

特點

支持 LinearLayoutManager、GridLayoutManager 和 StaggeredGridLayoutManager 

swipe 的開啟和關閉功能

不會攔截item的touch事件 

易擴展,我們知識override了RecyclerView的onInterceptTouchEvent(MotionEvent ev)方法。

項目地址: https://github.com/TUBB/SwipeMenuRecyclerView

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!