BRVAH 拖动 + 删除

 OnItemDragListener listener = new OnItemDragListener() {
     @Override
     public void onItemDragStart(RecyclerView.ViewHolder viewHolder, int pos){}
     @Override
     public void onItemDragMoving(RecyclerView.ViewHolder source, int from, RecyclerView.ViewHolder target, int to) {}
     @Override
     public void onItemDragEnd(RecyclerView.ViewHolder viewHolder, int pos) {}
 };

 OnItemSwipeListener onItemSwipeListener = new OnItemSwipeListener() {
     @Override
     public void onItemSwipeStart(RecyclerView.ViewHolder viewHolder, int pos) {}
     @Override
     public void clearView(RecyclerView.ViewHolder viewHolder, int pos) {}
     @Override
     public void onItemSwiped(RecyclerView.ViewHolder viewHolder, int pos) {}

     @Override
     public void onItemSwipeMoving(Canvas canvas, RecyclerView.ViewHolder viewHolder, float dX, float dY, boolean isCurrentlyActive) {
         // item 滑动的过程
         canvas.drawColor(ContextCompat.getColor(Main2Activity.this,R.color.colorAccent));
     }
 };

 ItemDragAndSwipeCallback itemDragAndSwipeCallback = new ItemDragAndSwipeCallback(adapter);
 ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemDragAndSwipeCallback);
 itemTouchHelper.attachToRecyclerView(mRecycler);

adapter.enableSwipeItem();
 adapter.setOnItemSwipeListener(onItemSwipeListener);
 // open drag
 adapter.enableDragItem(itemTouchHelper);
 adapter.setOnItemDragListener(listener);

 mRecycler.setAdapter(adapter);

你可能感兴趣的:(BRVAH 拖动 + 删除)