SwipeMenuRecyclerView

介绍:

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)方法。

已下载
0