我有一个水平的RecyclerView
。我需要滚动它但要通过滑动手势禁用 throw 。
最初所有工作都是在 onTouchEvent
方法中完成的,我不知道如何在不重写所有触摸处理的情况下禁用它
最佳答案
您可以将 GestureDetector
与 SimpleOnGestureListener
一起使用来捕获 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));
关于android - 如何禁用 RecyclerView fling 但保持滚动工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53340460/