首先看下要实现的效果
itemTouchHelper
ItemTouchHelper是RecyclerView.ItemDecoration的子类,它处理好了关于在RecyclerView上添加拖动排序与滑动删除的所有事情。它还可以和现有的item动画一起工作,提供受类型限制的拖放动画等。
itemTouchHelper=new ItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(recyclerView);//绑定RecycleView
构造函数需要传递callback;绑定RecycleView
RecycleItemTouchCallBack callback=new RecycleItemTouchCallBack(adapter);
这个callback为RecycleItemTouchCallBack
public class RecycleItemTouchCallBack extends ItemTouchHelper.Callback {
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
return 0;
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public