RecyclerView ItemTouchHelper如何锁定滑动项目? [英] How can RecyclerView ItemTouchHelper lock swipe item?

查看:241
本文介绍了RecyclerView ItemTouchHelper如何锁定滑动项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将RecyclerView与ItemTouchHelper一起使用以进行擦除以删除,并在滑动项下添加删除按钮,如下所示:

I use RecyclerView with ItemTouchHelper to do swiping to remove, and add delete button under the swipe item like this:

但是当我完成刷卡后,该项目很快就会从列表中删除! 如何锁定已刷卡的项目,然后单击删除"按钮将其删除? 就像Gmail的行为一样.

But when I finish swiping, the item will be removed from the list soon! How can I lock the swiped item, and removed by clicking the delete button? Just like Gmail's behavior.

ps.我在这里发布同样的问题

ps. I post same issues here https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=189057

推荐答案

@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    float translationX;
    if(dX > 0){
      translationX = Math.min(-dX, viewHolder.itemView.getWidth() / 2);
    }
    else {
       translationX = Math.max(dX, (-1)* viewHolder.itemView.getWidth() / 2);
    }
    super.onChildDraw(c, recyclerView, viewHolder, translationX, dY, actionState, isCurrentlyActive);
}

这篇关于RecyclerView ItemTouchHelper如何锁定滑动项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆