Phonegap 屏幕尺寸 (android)

Phonegap screen dimension (android)

我使用 Phonegap 为 Android 申请了 HTML5。 Phone 尺寸为 480 x 800。Javascript returns 屏幕宽度 480 (screen.width)。但是 480px 宽度的内容比屏幕大。当我用 width = 320 硬编码这个元素时,它看起来不错。

例如:

<div style="width:480px;border:#000000 1px solid">It's bigger than screen</div>            
<div style="width:320px;border:#000000 1px solid">It's looking good</div>

我应该使用哪种方式获取宽度?或者 Phonegap?

中有一些配置参数

阅读本文以了解:http://www.quirksmode.org/blog/archives/2010/04/a_pixel_is_not.html

480 是设备的物理像素宽度,320 是页面的 css 宽度。让您的页面在相同大小和不同密度的设备上以相同方式显示是一个技巧。

csswidth = screen.width / window.devicePixelRatio

要获得 CSS 宽度,我们必须将屏幕宽度(因为它是全屏应用程序)除以设备像素比。

480/1.5=320。好的。