如何让WVGA Android浏览器停止缩放图像?

Dan*_*ich 22 browser android webkit highdpi

我正在设计一个HTML页面,以便在Android浏览器中显示.考虑这个简单的示例页面:

<html>
<head><title>Simple!</title>
</head>
<body>
<p><img src="http://sstatic.net/so/img/logo.png"></p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

它在标准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;" />
Run Code Online (Sandbox Code Playgroud)

...但所有这一切都是禁用用户缩放(缩放按钮消失); 它实际上并没有阻止浏览器缩放我的图像.调整比例因子(将它们全部设置为2.0或0.5)完全没有效果.

如何强制WVGA浏览器停止缩放图像?

Dan*_*ich 32

啊,通过搜索Android源代码找到它."viewport"元标记中提供了一个新的特定于Android的" target-densityDpi "设置; 据我所知,除了办理登机手续的评论外,它完全没有记录!

为WebView添加dpi支持.

在"viewport"元标记中,您可以指定"target-densityDpi".如果未指定,则使用默认的160dpi.然后,视口标记中指定的1.0比例因子意味着G1上为100%,Sholes上为150%.如果将"target-densityDpi"设置为"device-dpi",则1.0比例因子在G1和Sholes上均为100%.

实现了Safari的window.devicePixelRatio和css媒体查询设备像素比.

因此,如果您使用"device-dpi"并根据window.devicePixelRatio修改font-size和image src的css,您可以在Sholes/Passion上获得更好的页面.

以下是"target-densityDpi"的选项列表.

device-dpi:使用设备的本机dpi作为目标dpi.low-dpi:120dpi medium-dpi:160dpi,这也是今天高dpi的默认值:240dpi:我们将70到400之间的任何数字作为有效目标dpi.

  • 不确定它是否有所作为,但文档没有大写任何一个 - 它的目标密度dpi不是target-densityDpi,如<meta name ="viewport"content ="target-densitydpi = device-dpi"/> http:/ /developer.android.com/reference/android/webkit/WebView.html (2认同)

use*_*682 5

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