android - 如何判断一个WebView是否一直缩小

标签 android webview scroll zooming

我正在寻找一种方法来检测 WebView 是否完全缩小。我知道您可以从 ZoomOut() 获得 bool 返回值,但这将执行缩小。我只想简单地知道它是否可以。

最佳答案

我使用自定义 WebView 类。

获取WebView的 View 高度和内部html网页的contentHeight

计算 defaultScale = WebView.getHeight()/WebView.getContentHeight();currentScale = WebView.getScale()

如果 defaultScale <currentScale 它被缩放。

public class NoZoomControllWebView extends WebView {

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @SuppressWarnings("deprecation")
    public boolean isZoomed () {
        boolean result = false;

        int contentHeight = getContentHeight();
        int viewHeight = getHeight();

        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1 ) {
            float scale = getScale();
            int temp = (int)(((float)viewHeight / (float)contentHeight) * 100);

            if (temp < (int)(scale * 100)) {
                result = true;
            }
        } else {
            float scale = getScale();
            int temp = (int)(((float)viewHeight / (float)contentHeight) * 100);

            if (temp < (int)(scale * 100)) {
                result = true;
            }
        }

        return result;
    }
}

关于android - 如何判断一个WebView是否一直缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4610715/

相关文章:

jquery - Smoothscroll.js 阻止 Opera 上的滚动,但如果删除会破坏粘性标题

java - 为什么我会收到此错误(未知标记 < :color> )even when there's no such tag in the file?

java - 文本转语音 Android Studio

javascript - 安卓-Javascript : how to execute jquery in webview

webview - Window.open() 在 WKWebView 中不起作用

jquery-ui - Jquery UI 1.10.x 对话框在大 body 高度上的拖动问题

Android 退出 toast

android - 单击按钮时将图像向左/向右旋转一定角度

cocoa - 显式设置 WebFrame 的数据源

html - 使用具有背景附件 : fixed 属性的图像屏蔽 div