【问题标题】:how to implement gesture detector onfling in webview in android如何在android的webview中实现手势检测器onfling
【发布时间】:2011-03-01 12:52:29
【问题描述】:

谁能举例说明如何在android的webview中实现手势检测器onfling

谢谢

【问题讨论】:

    标签: android gesture-recognition onfling gesturedetector


    【解决方案1】:

    我从某个地方找到了这条路:

    要在 WebView 中检测到手势,无需子类化任何东西。你只需要在你的活动中添加这个:

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

    mGestureDetector 在 onCreate() 中被初始化为新的 GestureDetector(this)。 这将拦截所有手势事件,让您的听众有机会做任何您想做的事情,并将其发送回 WebView,因此行为不会受到影响。

    【讨论】:

      【解决方案2】:

      今天才完成:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多