初学者使用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);
或者也可以通过文章源自IT老刘-https://itlao6.com/687.html
settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
原文:简书ThinkinLiu 博客: IT老五文章源自IT老刘-https://itlao6.com/687.html
另外,WebView中文字大小也可以进行调整,通过以下方法可以调整文字大小:文章源自IT老刘-https://itlao6.com/687.html
settings.setTextZoom(100);
中间int参数是指字体与原大小的百分比。文章源自IT老刘-https://itlao6.com/687.html 文章源自IT老刘-https://itlao6.com/687.html
我的微信公众号
微信扫一扫关注公众号,不定时更新
评论