android - 如何禁用 RecyclerView fling 但保持滚动工作?

标签 android android-recyclerview fling

我有一个水平的RecyclerView。我需要滚动它但要通过滑动手势禁用 throw 。

最初所有工作都是在 onTouchEvent 方法中完成的,我不知道如何在不重写所有触摸处理的情况下禁用它

最佳答案

您可以将 GestureDetectorSimpleOnGestureListener 一起使用来捕获 Fling 事件并决定是否允许它们。

RecyclerView recycler = findViewById(R.id.recycler);
GestureDetector detector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        // return true if you want to stop the fling
        // return false if you want to allow the fling
        return true;
    }
});

recycler.setOnTouchListener((v, event) -> detector.onTouchEvent(event));

GestureDetector.OnGestureListener#onFling()

关于android - 如何禁用 RecyclerView fling 但保持滚动工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53340460/

相关文章:

android - 如何等待 ListAdapter.submitList() 执行并调用 RecyclerView.smoothScrollToPosition(0);

android - 如何使用 StaggeredGridLayoutManager 在 recyclerview 中实现无限滚动(分页)

android - 如何去除 appbar 的弹跳效果?

react-native - 调用外部函数时,GestureDetector 手势处理程序应用程序崩溃

android - 如何将公历日期转换为伊斯兰(回历)日期?

android - 验证点是否被圈出的算法

javascript - Cordova Android 禁用后退按钮 [不起作用]

java - Android - 自定义 ListView 创建正确数量的条目,但仅填充第一个条目

android - GridLayoutManager 间距不一致