WebView getting rid of double tap zoom.

后端 未结 6 956
悲&欢浪女
悲&欢浪女 2020-12-19 03:18

I read many tickets on the topic of Zooming in WebViews and didnt came to an answer for my case.

Here´s my setup:

I´m using a custom webview with generally

6条回答
  •  臣服心动
    2020-12-19 03:49

    There are two methods to achieve your goal:

    Method 1

    Implement the GestureDetector.OnDoubleTapListener like this:

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
      return false; //Nothing
    }
    
    @Override
    public boolean onDoubleTap(MotionEvent e) {
      //Indicates that this implementation has handled the double tap.
      return true;
    }
    
    @Override
    public boolean onDoubleTapEvent(MotionEvent e) {
      //Indicates that this implementation has handled the double tap.
      return true;
    }
    

    and attach it to your GestureDetector like this:

    gestureDetector.setOnDoubleTapListener(this);
    

    Method 2

    You can also use the WebSettings.setUseWideViewPort(false); and calculate the size of your view manually.

    These methods should help you to achieve non-zoomable webviews that display everything.

    public int getWindowWidth(Activity activity) {
      Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
      Point size = new Point();
      display.getSize(size);
      int width = size.x;
      return width;
    }
    
    public int getInitialScale(Activity activity, int websiteWidth) {
      return (getWindowWidth(activity) / websiteWidth) * 100;
    }
    

提交回复
热议问题