android - 在 Android WebView 中启用/禁用缩放

标签 android android-webview zooming multi-touch

WebSettings中有一些与缩放相关的方法:

  • WebSettings.setSupportZoom
  • WebSettings.setBuiltInZoomControls

我注意到它们在某些设备上的工作方式不同。 例如,在我的 Galaxy S 上,默认启用双指缩放,但在 LG P500 上它被禁用(现在我不知道如何启用仅双指缩放,但隐藏缩放按钮)。

在 P500 上,当我调用 setBuiltInZoomControls(true) 时,这两种变体都能正常工作(多点触控和按钮)。

如何在 LG P500 等设备上启用多点触控缩放和禁用缩放按钮? (另外,我知道 HTC 设备上也存在同样的问题)

更新:这里几乎是解决方案的完整代码

if (ev.getAction() == MotionEvent.ACTION_DOWN ||
        ev.getAction() == MotionEvent.ACTION_POINTER_DOWN ||
        ev.getAction() == MotionEvent.ACTION_POINTER_1_DOWN ||
        ev.getAction() == MotionEvent.ACTION_POINTER_2_DOWN ||
        ev.getAction() == MotionEvent.ACTION_POINTER_3_DOWN) {
    if (multiTouchZoom && !buttonsZoom) {
        if (getPointerCount(ev) > 1) {
            getSettings().setBuiltInZoomControls(true);
            getSettings().setSupportZoom(true);
        } else {
            getSettings().setBuiltInZoomControls(false);
            getSettings().setSupportZoom(false);
        }
    }
}

if (!multiTouchZoom && buttonsZoom) {
    if (getPointerCount(ev) > 1) {
        return true;
    }
}

此代码在我的 WebView 的 onTouchEvent 重写方法中。

最佳答案

在 API >= 11 上,您可以使用:

wv.getSettings().setBuiltInZoomControls(true);
wv.getSettings().setDisplayZoomControls(false);

根据 SDK:

public void setDisplayZoomControls (boolean enabled) 

Since: API Level 11

Sets whether the on screen zoom buttons are used. A combination of built in zoom controls enabled and on screen zoom controls disabled allows for pinch to zoom to work without the on screen controls

关于android - 在 Android WebView 中启用/禁用缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5125851/

相关文章:

android - 饼图 : how to display text just on some pie slices using AChartEngine Android library?

android - Android 上使用了哪些架构模式?

android - 找不到包 : com. android.chrome

android - 渲染进程崩溃 webview Android Pie (9)

java - 如何在所有缩放级别实时准确地绘制大数据 vector ?

UIScrollView contentLayoutGuide 和缩放居中

javascript - jquery 缩放和轮播购物模块错误

java - 关闭时使用 Firebase 保持应用登录状态

Android 在 WebView 中显示 .Doc 文件?

java - 从广播接收器更新或附加 TextView