且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android在WebView活动中向左/向右滑动手势(单击链接和垂直滚动)

更新时间: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.