문제

can anybody give example how to implement gesture detector onfling in webview in android

Thanks

도움이 되었습니까?

해결책

I find this way from somewhere:

To have the gesture detected in a WebView, no need to subclass anything. You just need to add this in your activity:

@Override
public boolean dispatchTouchEvent(MotionEvent e){
    super.dispatchTouchEvent(e);
    return mGestureDetector.onTouchEvent(e);
}

Where mGestureDetector is initialized as new GestureDetector(this) on your onCreate(). This will intercept all the gesture events, give opportunity to your listener to do whatever your want with it, and send it back to WebView so behaviour won’t be affected.

다른 팁

Done that just today:

private final GestureDetector mGestureDetector = new GestureDetector(new CustomGestureListener());

@Override
public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);
    return mGestureDetector.onTouchEvent(event);
}

private class CustomGestureListener extends GestureDetector.SimpleOnGestureListener {
    // override this method: onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top