我正在设计一个用于在 Android 浏览器中显示的 HTML 页面。考虑这个简单的示例页面:
<html>
<head><title>Simple!</title>
</head>
<body>
<p><img src="http://sstatic.net/so/img/logo.png"></p>
</body>
</html>
它在标准 HVGA 手机 (320x480) 上看起来很好,但在 HDPI WVGA 尺寸(480x800 或 480x854)上,内置浏览器会自动放大图像;它看起来很难看。
我读过,我应该能够使用此标签来强制浏览器停止缩放我的页面:
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=0;" />
...但所做的只是禁用用户缩放(缩放按钮消失);它实际上并没有阻止浏览器缩放我的图像。调整比例因子(将它们全部设置为 2.0 或 0.5)根本没有效果。
如何强制 WVGA 浏览器停止缩放图像?
I'm designing an HTML page for display in Android browsers. Consider this simple example page:
<html>
<head><title>Simple!</title>
</head>
<body>
<p><img src="http://sstatic.net/so/img/logo.png"></p>
</body>
</html>
It looks just fine on the standard HVGA phones (320x480), but on HDPI WVGA sizes (480x800 or 480x854) the built-in browser automatically scales the image up; it looks ugly.
I've read that I should be able to use this tag to force the browser to stop scaling my page:
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=0;" />
... but all that does is disable user scaling (the zoom buttons disappear); it doesn't actually prevent the browser from scaling my image. Adjusting the scale factors (setting them all to 2.0 or 0.5) has no effect at all.
How can I force the WVGA browser to stop scaling my images?
发布评论
评论(2)
啊,通过搜索Android源码找到了。有一个新的 Android 特定的“目标-密度Dpi”设置可在“viewport”元标记中使用;据我所知,除了签入评论之外,它完全没有记录!
Ah, found it by searching through the Android source code. There's a new Android-specific "target-densityDpi" setting available in the "viewport" meta tag; as far as I can tell, it's totally undocumented, except for the check-in comment!
它现在是 WebView API 文档的一部分:http://developer.android。 com/reference/android/webkit/WebView.html
请参阅标题为构建网页以支持不同屏幕密度的部分
It's now part of the API documentation for the WebView: http://developer.android.com/reference/android/webkit/WebView.html
See the section entitled Building web pages to support different screen densities