在某些大分辨率下,我们用WebView加载的网页可能会出现被放大的现象,这显然不是我们想要的结果,我开始看WebSettings这个是否可以设置不缩放,webSettings.setBuiltInZoomControls(false),我发现这样设置后没有任何效果,没办法只得继续看代码。后来看到有个这样的属性:WebSettings.ZoomDensity
才最终解决这个问题(网址如下:http://www.android-/reference/android/webkit/WebSettings.ZoomDensity.html)
下面直接贴关键部分的代码吧。
int screenDensity = getResources().getDisplayMetrics().densityDpi;Logger.d(TAG, "screenDensity = " + screenDensity);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:case DisplayMetrics.DENSITY_XHIGH:case DisplayMetrics.DENSITY_XXHIGH:default:zoomDensity = WebSettings.ZoomDensity.FAR;break;}webSettings.setDefaultZoom(zoomDensity);