DynamicRecyclerView

介绍:

一个轻量级的,非侵入式的方式实现RecyclerView拖拽排序,滑动删除的库,非侵入式的意思是指它没有使用自定义的RecyclerView或者是LayoutManager,所以适用范围更广。该库的意义不在于其实现了拖拽排序和滑动删除,而在于其实现方式。

运行效果:

使用说明:

拖拽

    dragDropTouchListener = new DragDropTouchListener(recyclerView, this) {        @Override
        protected void onItemSwitch(RecyclerView recyclerView, int from, int to) {
            adapter.swapPositions(from, to);
            adapter.notifyItemChanged(to);
            adapter.notifyItemChanged(from);
         @Override
         protected void onItemDrop(RecyclerView recyclerView, int position) {
        }
   };
   }
    recyclerView.addOnItemTouchListener(dragDropTouchListener);

滑动删除

 swipeToDismissTouchListener = new SwipeToDismissTouchListener(recyclerView, new SwipeToDismissTouchListener.DismissCallbacks() {            @Override
           public SwipeToDismissTouchListener.SwipeDirection canDismiss(int position) {               return SwipeToDismissTouchListener.SwipeDirection.RIGHT;
           }            @Override
           public void onDismiss(RecyclerView view, List<SwipeToDismissTouchListener.PendingDismissData> dismissData) {              for (SwipeToDismissTouchListener.PendingDismissData data : dismissData) {
                  adapter.removeItem(data.position);
                  adapter.notifyItemRemoved(data.position);
              }
           }
   });
  recyclerView.addOnItemTouchListener(swipeToDismissTouchListener);
已下载
0