如何在android中的webview中实现手势检测器onfling

发布于 2024-10-04 03:13:27 字数 66 浏览 0 评论 0原文

任何人都可以举例说明如何在 android 的 webview 中实现手势检测器 onfling

谢谢

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

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

他不在意 2024-10-11 03:13:27

我从某个地方找到了这种方法:

要在 WebView 中检测到手势,不需要子类化任何内容。您只需将其添加到您的活动中:

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

其中 mGestureDetector 在您的 onCreate() 上初始化为 new GestureDetector(this) 。
这将拦截所有手势事件,让您的侦听器有机会对其执行任何您想要的操作,并将其发送回 WebView,以便行为不会受到影响。

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.

计㈡愣 2024-10-11 03:13:27

今天刚做的:

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)
}

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)
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文