Android WebView文字大小调整及页面缩放调整

2019-05-21 12:38:57

参考地址 Android WebView文字大小调整及页面缩放调整

初学者使用webview难免会面对页面缩放,展示与预期不符的问题,这里有几个处理方案:

方案一、通过屏幕密度调整分辨率
        WebSettings settings = mWebView.getSettings();       int screenDensity = getResources().getDisplayMetrics().densityDpi;
        WebSettings.ZoomDensity zoomDensity = WebSettings.ZoomDensity.MEDIUM;        switch (screenDensity) {            case DisplayMetrics.DENSITY_LOW:
                zoomDensity = WebSettings.ZoomDensity.CLOSE;                break;            case DisplayMetrics.DENSITY_MEDIUM:
                zoomDensity = WebSettings.ZoomDensity.MEDIUM;                break;            case DisplayMetrics.DENSITY_HIGH:
                zoomDensity = WebSettings.ZoomDensity.FAR;                break;
        }
        settings.setDefaultZoom(zoomDensity);
方案二、设置自适应
        settings.setUseWideViewPort(true); 
        settings.setLoadWithOverviewMode(true);

或者也可以通过

        settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

原文:简书ThinkinLiu 博客: IT老五

另外,WebView中文字大小也可以进行调整,通过以下方法可以调整文字大小:

        settings.setTextZoom(100);

中间int参数是指字体与原大小的百分比。



  • 2017-11-06 01:00:17

    撤销git add

    如何撤销git add,不小心执行了git add . 操作,但是又不能提交所有的文件,因为对应不同的分支,现在怎么样可以将git add 撤销回来

  • 2017-11-10 00:06:15

    CORS: credentials mode is 'include'

    XMLHttpRequest cannot load http://localhost/Foo.API/token. The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:5000' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.