其他分享
首页 > 其他分享> > android – 如何控制webView中的缩放

android – 如何控制webView中的缩放

作者:互联网

我有这个代码:

[...]
{
    webView = (WebView) findViewById(R.id.webView1);
    webView.setInitialScale(getScale(Double.parseDouble(pubPages)));
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.setPadding(0, 0, 0, 0);

    webView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress)
        {
            activity.setTitle("Loading...");
            activity.setProgress(progress * 100);

            if(progress == 100)
                activity.setTitle(R.string.app_name);
        }
    });

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
        {
            // Handle the error
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            view.loadUrl(url);
            return true;
        }
    });

    webView.loadUrl("http://urltoshow");
}

private int getScale(double numPages){
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int screenHeight = dm.heightPixels;

    Double val = (new Double(screenHeight-40)/(new Double(1024)));    
    val = val * 100d;
    return val.intValue();
}

它工作正常,但我想禁止在自然高度以下放大侧面.

放大是,缩小是但是最多一点.

这个怎么做?

解决方法:

 webview.getSettings().setBuiltInZoomControls(true);

标签:zooming,android,webview,android-webview
来源: https://codeday.me/bug/20190927/1823995.html