我有一个带有CardView的Recycleview,并且为此实现了一个滑动手柄选项。当用户向右滑动时,该卡需要删除。问题是该操作非常敏感-单击或拖动卡时会执行该操作。仅当您将卡拖动到屏幕末端时,如何才能解决此问题以使其不那么敏感?
答案 0 :(得分:1)
仅在类ItemTouchHelper.Callback中重写方法getSwipeEscapeVelocity():
public class SwipeToDeleteTouchHelperCallback extends ItemTouchHelper.SimpleCallback {
//constructor, another methods, etc...
@Override
public float getSwipeEscapeVelocity(float defaultValue) {
return defaultValue * 10;//10 -> almost insensitive
}
}
如果要更改“划动边界”,请重写此类中的另一种方法:
@Override
public float getSwipeThreshold(@NonNull RecyclerView.ViewHolder viewHolder) {
// 0.75 - you need to drag item by 75% of his width(or height) to dismiss
// default value is 0.5f
return 0.75f;
}