这是我的问题,我有一个RecyclerView,我必须处理长按,滚动和移动事件。基本上我想在用户滚动时拦截长按。当长按时我想拦截滚动但是在长按后继续对ACTION_MOVE做一些动作。这就是我到目前为止所拥有的
recyclerView.setOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
// Release the scroll.
mIsScrolling = false;
gestureDetectorCompat.onTouchEvent(ev);
return false;
}
if(action == MotionEvent.ACTION_MOVE) {
// when user scrolls it comes here
return true; // to handle scroll on onTouchEvent
}
}
public void onRequestDisallowInterceptTouchEvent(boolean disallow) {
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
//never comes here after return true onInterceptTouchEvent
}
});
初始化gestureDetectorCompat
gestureDetectorCompat = new GestureDetectorCompat(context,getOnGestureListener());
public GestureDetector.SimpleOnGestureListener getOnGestureListener() {
return new GestureDetector.SimpleOnGestureListener(){
@Override
public void onLongPress(MotionEvent e) {
if(!mIsScrolling)
//do something
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
mIsScrolling = true;
return true;
}
};
}
这个主题我到目前为止检查过但在我的情况下对回收者视图没有帮助
Android long press with scroll
感谢您的帮助。