Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何实现在webview中使用手势?_Android_Webview_Onfling - Fatal编程技术网

Android 如何实现在webview中使用手势?

Android 如何实现在webview中使用手势?,android,webview,onfling,Android,Webview,Onfling,我在webview中加载图像,并希望通过抛出手势在它们之间切换,但在webview中实现手势检测器的情况下,所有事件都由检测器确定=webview功能,因为缩放和mt不起作用。有什么解决办法吗?过滤事件并将其传递给ontouch?示例代码非常宝贵 感谢大家。关键是检查gestureDetector.onTouchEvent的返回值,如果gestureDetector没有处理该事件,则将其传递给WebView超类。此外,即使您对onDown方法执行了某些操作,也要确保从该方法返回false,这样超

我在webview中加载图像,并希望通过抛出手势在它们之间切换,但在webview中实现手势检测器的情况下,所有事件都由检测器确定=webview功能,因为缩放和mt不起作用。有什么解决办法吗?过滤事件并将其传递给ontouch?示例代码非常宝贵


感谢大家。

关键是检查gestureDetector.onTouchEvent的返回值,如果gestureDetector没有处理该事件,则将其传递给WebView超类。此外,即使您对onDown方法执行了某些操作,也要确保从该方法返回false,这样超类就可以初始化其内部状态。如果onFling方法处理事件,则返回true,否则返回false,以便应用默认方法

public class FlingView extends WebView implements OnGestureListener {

    private GestureDetector gestureDetector;

    public FlingView(Context context) {
        super(context);
        init();
    }

    public void init() {
        gestureDetector = new GestureDetector(this.getContext(), this);
    }

    @Override
    public boolean onTouchEvent(MotionEvent e) {
        return (
        gestureDetector.onTouchEvent(e) || super.onTouchEvent(e));
    }

    /* OnGestureListener events */

    public boolean onDown(MotionEvent e1) {
        // Initialize event here
        ...

        // give the superclass a chance at tap events
        return false;
    }

    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
    float velocityY) {
        if (test) {
            // handle fling
            ...
            return true;
        } else {
            // let superclass handle the event
            return false;
        }
    }
}

关键是检查gestureDetector.onTouchEvent的返回值,如果gestureDetector没有处理该事件,则将其传递给WebView超类。此外,即使您对onDown方法执行了某些操作,也要确保从该方法返回false,这样超类就可以初始化其内部状态。如果onFling方法处理事件,则返回true,否则返回false,以便应用默认方法

public class FlingView extends WebView implements OnGestureListener {

    private GestureDetector gestureDetector;

    public FlingView(Context context) {
        super(context);
        init();
    }

    public void init() {
        gestureDetector = new GestureDetector(this.getContext(), this);
    }

    @Override
    public boolean onTouchEvent(MotionEvent e) {
        return (
        gestureDetector.onTouchEvent(e) || super.onTouchEvent(e));
    }

    /* OnGestureListener events */

    public boolean onDown(MotionEvent e1) {
        // Initialize event here
        ...

        // give the superclass a chance at tap events
        return false;
    }

    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
    float velocityY) {
        if (test) {
            // handle fling
            ...
            return true;
        } else {
            // let superclass handle the event
            return false;
        }
    }
}