简体   繁体   English

使用ItemTouchHelper的RecyclerView仅可部分滑动

[英]RecyclerView with ItemTouchHelper only part swipeable

I have a recyclerview list with items like this: 我有一个带有以下内容的recyclerview列表:

项目清单

The red square only can we swiped (drag and drop out) to the left, and the green only can we swiped to the right. 红方只有我们可以刷卡(拖放出)向左,绿色只能刷卡,我们的权利。 When the element is swiped, appear and image with a option like this: 滑动元素后,出现并显示带有以下选项的图像:

-swipe left: -向左滑动:

向左滑动

-swipe right: -向右滑动: 向右滑动

The layout item have this appearance: 布局项目具有以下外观:

<RelativeLayout>
   <LinearLayout>
      <ImageView/> //Red square
      <ImageView/>  //Green square
   </LinearLayout>
   <LinearLayout>
      <ImageView/>  //Red square swiped action
      <ImageView/>  //Green square swiped action
   </LinearLayout>
</RelativeLayout>

I'm trying to do this with ItemTouchHelper.Callback and overriding the method onChildDraw to make the correct animation. 我正在尝试使用ItemTouchHelper.Callback并重写onChildDraw方法以制作正确的动画。 But I can't hold with square has be swiped, and make the correct animation. 但是我不能忍受已经被广场擦过,并做出正确的动画。 ¿Another way to achieve this? ¿实现此目的的另一种方法?

Based on a lot of examples, it's easy by creating you own Callback listener in RecycleView. 根据大量示例,在RecycleView中创建您自己的回调侦听器很容易。 Just as in this example . 就像在这个例子中一样 You need to provide you own behavior. 您需要提供自己的行为。

Example of SimpleItemTouchHelperCallback from link above. 上面链接中的SimpleItemTouchHelperCallback示例。

    @Override
    public int getMovementFlags(RecyclerView recyclerView, ViewHolder viewHolder) {
        int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
        int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;

        //Four your Red field use flags
        int redFlags = ItemTouchHelper.START;

        //Four your Green field use flags
        int greenFlags = ItemTouchHelper.END;

        return makeMovementFlags(dragFlags, swipeFlags);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM