gpt4 book ai didi

android - 如何让 WVGA Android 浏览器停止缩放我的图像?

转载 作者:IT老高 更新时间:2023-10-28 22:25:37 26 4
gpt4 key购买 nike

我正在设计一个在 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 浏览器停止缩放我的图像?

最佳答案

啊,通过搜索Android源代码找到的。 “viewport”元标记中有一个新的 Android 特定“target-densityDpi”设置;据我所知,除了 checkin 评论之外,它完全没有记录!

Add dpi support for WebView.

In the "viewport" meta tag, you can specify "target-densityDpi". If it is not specified, it uses the default, 160dpi as of today. Then the 1.0 scale factor specified in the viewport tag means 100% on G1 and 150% on Sholes. If you set "target-densityDpi" to "device-dpi", then the 1.0 scale factor means 100% on both G1 and Sholes.

Implemented Safari's window.devicePixelRatio and css media query device-pixel-ratio.

So if you use "device-dpi" and modify the css for font-size and image src depending on window.devicePixelRatio, you can get a better page on Sholes/Passion.

Here is a list of options for "target-densityDpi".

device-dpi: Use the device's native dpi as target dpi. low-dpi: 120dpi medium-dpi: 160dpi, which is also the default as of today high-dpi: 240dpi : We take any number between 70 and 400 as a valid target dpi.

关于android - 如何让 WVGA Android 浏览器停止缩放我的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2796814/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com