的WebView摆脱双击缩放。 [英] WebView getting rid of double tap zoom.

查看:124
本文介绍了的WebView摆脱双击缩放。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读拉近WebViews,并没有专题几张票来对我的情况的答案。

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

Here's我的设置:

Here´s my setup:

I'm使用与通常这些设置的自定义的WebView:

I´m using a custom webview with generally these settings:

getSettings().setBuiltInZoomControls(false);
getSettings().setSupportZoom(false);
getSettings().setUseWideViewPort(true);
getSettings().setLoadWithOverviewMode(true);

让我注意在这里,我依赖于OverviewMode和以及对WideViewPort为标尺我的WebView。

Let me note right here that i depend on OverviewMode and as well on WideViewPort to Scale my WebView.

I'm还覆盖我的onTouchEvent并和代表所有适当的活动,以一个手势检测:

I´m also Overriding my OnTouchEvent and and delegate all suitable events to an Gesture detector:

  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (gestureDetector.onTouchEvent(event)) return true;
    return super.onTouchEvent(event);
  }

下面是它的听众的实现,它是拦截所有doubleTap事件:

Here is its listeners implementation which is intercepting all doubleTap events:

  @Override
  public boolean onDoubleTapEvent(MotionEvent e) {
    // Do nothing! 
    return true;
  }

  @Override
  public boolean onDoubleTap(MotionEvent e) {
    // Do nothing! 
    return true;
  }

  @Override
  public boolean onSingleTapConfirmed(MotionEvent e) {
    // Do nothing! 
    return true;
  }

此外,我推翻了放大有关这些2的WebView方法:

Also i overrode these 2 WebView methods related to zoom:

  @Override
  public boolean zoomIn() {
    return true;
  }

  @Override
  public boolean zoomOut() {
    return true;
  }

Notherless所有这些选项的某自来水频会导致我的WebView来放大/缩小。 我还没有发现禁用这种缩放的选项,MotionEvent这个放大似乎没有适用于该GestureDetector和覆盖zoomIn()zoomOut()方法没有任何效果。

Notherless of all these options a certain tap frequence will cause my webview to zoom in/out. I havent found an option that disables this kind of zooming, the MotionEvent for this Zoom doesnt seem to be applicable for the GestureDetector and the override zoomIn() zoomOut() methods have no effect either.

谁能帮我出一个办法来避免这种双击缩放的WebView的behaivior?

Can anyone help me out with a way to avoid this double tap zoom behaivior of WebView?

推荐答案

有两种方法来实现自己的目标:

There are two methods to achieve your goal:

方法1

实施 GestureDetector.OnDoubleTapListener 是这样的:

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

和它连接到你的 GestureDetector 是这样的:

and attach it to your GestureDetector like this:

gestureDetector.setOnDoubleTapListener(this);

方法2

您也可以使用 WebSettings.setUseWideViewPort(假); 和计算手动视图的尺寸

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

这些方法可以帮助你实现这一显示所有非可缩放webviews。

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

这篇关于的WebView摆脱双击缩放。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆