开发者

How implement fling gestures into webview?

I load images in webview and would like to switch between them by fling gesture, but implementing gesture detector in webview case all events are caugth by detector = webview function as zoom and mt dont work. Is there any solution? Filtering events and passing them dow to ontouch? Example code v开发者_C百科ery apreciated.

Thanks to all.


The key to this is to check the return value from gestureDetector.onTouchEvent and, if gestureDetector did not handle the event, then pass it on to the WebView superclass. Also, be sure to return "false" from your onDown method even if you do something with it, so the superclass can initialize its internal state. If your onFling method handles the event, return "true", otherwise return "false" so the default methods can apply.

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;
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜