前言
话不多说,直接上图:
笔者使用 RecyclerView
的 ItemTouchHelper
来实现这个效果,过程非常简单。
实现功能:
- 按住
item
左侧的按钮可以上下拖动item
- 向右侧滑删除
item
item
拖动或侧滑时有阴影效果
实现基本功能
循序渐进学习,这里我们先实现基本的功能:
- 长按
item
实现上下拖拽 - 向右侧滑删除
布局文件
很简单,不多说,直接上代码:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_recyclerView"
android:scrollbars="none"
android:background="#F2F8FC">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
item_list.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height