android - Swipe delete on Recycleview is very sensitive
问题描述
I have a Recycleview with CardView and I Implement to this a swipe handle option. When the user swipe right the card need to delete. The problem is that the action is very sensitive - When you click or drag a little bit the card it do the action. What can I do to fix that to be less sensitive, only if you drag the card until the end of the screen for example?
解决方案
Just override method getSwipeEscapeVelocity() in class ItemTouchHelper.Callback:
public class SwipeToDeleteTouchHelperCallback extends ItemTouchHelper.SimpleCallback {
//constructor, another methods, etc...
@Override
public float getSwipeEscapeVelocity(float defaultValue) {
return defaultValue * 10;//10 -> almost insensitive
}
}
If you want change "borderline of swipe", override another method in this class:
@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;
}
推荐阅读
- python - 使用python从CSV文件中删除空白单元格
- ansible - 如何在变量中获取主机别名?
- pymysql - 需要查询以在没有 WHERE 约束的情况下在一列中更改更多行
- c++ - char 数组及其指针如何在 C++ 中准确工作?
- android - 视图或视图模型是否负责将模型中的数据转换为在 UI 中呈现?
- bash - 了解如何将输入重定向到从文件构造时
- c# - 在 Linq to Sql 中使用 ExecuteCommand 与事务
- spring - Spring Cloud Config - 从 Git 读取多个属性文件
- python - 我如何将数据保存到文本文件中,主要是我在记录中写的内容
- python - 如何将json文件转换为列表