如何确定一个web视图被放大了所有的方法 [英] How to determine if a WebView is zoomed out all the way

查看:162
本文介绍了如何确定一个web视图被放大了所有的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来检测的WebView是否完全缩小。我知道你可以从ZoomOut()一个布尔返回值,但将进行缩小。我只是想简单地知道它是否可以。

I'm looking for a way to detect whether or not a WebView is zoomed out fully. I know you can get a boolean return value from ZoomOut(), but that will perform the zoom out. I just want to simply know whether or not it can.

推荐答案

我用我的自定义的WebView 类。

获取的WebView 的看法高度和内部HTML网页的或contentHeight

Get WebView's view height and inner html web page's contentHeight.

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

如果 defaultScale < currentScale 它放大。

If defaultScale < currentScale it's zoomed.

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

这篇关于如何确定一个web视图被放大了所有的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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