更新时间:2022-12-05 16:25:47
我对GestureDetector
不够熟悉,无法可靠地诊断您的问题.您可以尝试的一件事是克隆事件:
I'm not familiar enough with the GestureDetector
to reliably diagnose your problem. One thing you could try is cloning the event:
@Override
public boolean dispatchTouchEvent(MotionEvent ev){
onSwipeTouchListener.getGestureDetector().onTouchEvent(MotionEvent.obtain(ev));
return super.dispatchTouchEvent(ev);
}
Failing that another way to approach this is to use onOverScrolled instead of a GestureDetector
:
@Override
protected void onOverScrolled (int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
if (scrollX > (getWidth() + THRESHOLD) && clampedX) {
onSwipeLeft();
}
if (scrollX < - THRESHOLD && clampedX) {
onSwipeRight();
}
super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
}
这确实假定您的内容通常无法横向滚动.
This does assume that your content is not normally scrollable sideways though.