Android中WebView的默认缩放值是多少?
What is the default scale value of the WebView in Android?
Android doc 表示 getScale()
方法已弃用。
我已经实现了 onScaleChanged(WebView, float, float)
来获取新的比例,但是这个方法只有在比例改变时才会被触发。
那么,webview 的默认比例值是多少?
从 getScale()
方法来看,它是 2.0f
,但是这个值在所有设备上总是 2.0f 吗?
根据开发者 WebView documentation 的说法,缩放比例取决于设备屏幕上的像素密度:
By default, WebView scales a web page so that it is drawn at a size that matches the default appearance on a medium density screen. So, it applies 1.5x scaling on a high density screen (because its pixels are smaller) and 0.75x scaling on a low density screen (because its pixels are bigger). Starting with API level ECLAIR, WebView supports DOM, CSS, and meta tag features to help you (as a web developer) target screens with different screen densities.
更多信息可在页面 Supporting Different Screens in Web Apps 上找到,其中包含使用 JavaScript:
查询设备密度的信息(和示例代码)
if (window.devicePixelRatio == 1.5) {
alert("This is a high-density screen");
} else if (window.devicePixelRatio == 0.75) {
alert("This is a low-density screen");
}
Android doc 表示 getScale()
方法已弃用。
我已经实现了 onScaleChanged(WebView, float, float)
来获取新的比例,但是这个方法只有在比例改变时才会被触发。
那么,webview 的默认比例值是多少?
从 getScale()
方法来看,它是 2.0f
,但是这个值在所有设备上总是 2.0f 吗?
根据开发者 WebView documentation 的说法,缩放比例取决于设备屏幕上的像素密度:
By default, WebView scales a web page so that it is drawn at a size that matches the default appearance on a medium density screen. So, it applies 1.5x scaling on a high density screen (because its pixels are smaller) and 0.75x scaling on a low density screen (because its pixels are bigger). Starting with API level ECLAIR, WebView supports DOM, CSS, and meta tag features to help you (as a web developer) target screens with different screen densities.
更多信息可在页面 Supporting Different Screens in Web Apps 上找到,其中包含使用 JavaScript:
查询设备密度的信息(和示例代码)if (window.devicePixelRatio == 1.5) { alert("This is a high-density screen"); } else if (window.devicePixelRatio == 0.75) { alert("This is a low-density screen"); }