Android浏览器报告了错误的屏幕尺寸?浏览器、错误、报告、屏幕尺寸

2023-09-08 00:34:58 作者:孤独留给我

我开发一个移动网站,我遇到一个有趣的问题。

I am developing a mobile website, and I've come across an interesting issue.

我对我的摩托罗拉Droid(Android 2.2的)测试我的桌面上,以及。我已经设置了装载3种不同样式媒体查询(320像素宽,480像素宽,640像素宽)。我发现我的Droid正在加载320像素样式尽管有480x854px屏幕。我成立了一个小JS找出屏幕宽度是什么,它​​的报告320像素。

I'm testing on my desktop, as well as on my Motorola Droid (Android 2.2). I have media queries set up to load 3 different stylesheets (320px wide, 480px wide, and 640px wide). I noticed that my Droid is loading the 320px stylesheet despite having a 480x854px screen. I set up a little JS to find out what the screen width is, and it's reporting 320px.

在是否对MDPI屏幕华电国际在Android浏览器中运行?它的缩放320像素正确地填补了屏幕,但我有点困惑,为什么这种情况正在发生。

Does the Android browser run in MDPI on HDPI screens? It's scaling the 320px properly to fill the screen, but I'm a little confused why this is happening.

另外,我确实有< META NAME =视口CONTENT =WIDTH =设备宽度>我的网页上,所以这不是问题。

Also, I do have <meta name="viewport" content="width=device-width"> on my page, so that is not the issue.

推荐答案

许多OEM选择,尽管有一个完全不同的分辨率设置基于这些在iPhone(或类似决议)其默认浏览器窗口尺寸。苹果公司曾与视网膜显示器的对iPhone 4的发布类似的问题,其中规格表州跨越640像素,但会screen.width时设置返回320像素。

Many OEMs have chosen to set their default browser viewport dimensions based on those of the iPhone (or similar resolutions) despite having an altogether different resolution. Apple had a similar problem with the release of the 'retina display' on the iPhone 4 where the spec sheet states 640px across, but screen.width will return 320px when is set.

由于使用WURFL或的DeviceAtlas。@omermuhammed提到的基础上的逻辑screen.width,CSS @media查询和/或设备检测

As @omermuhammed mentioned base your logic on screen.width, CSS @media queries AND/OR device detection using WURFL or DeviceAtlas.

下面的文章也可能感兴趣在帮助澄清问题:

The following article may also be of interest in helping to clarify the issue:

一个像素不是像素不受@ppk像素 http://www.quirksmode.org/blog/archives/2010/04 /a_pixel_is_not.html

A pixel is not a pixel is not a pixel by @ppk http://www.quirksmode.org/blog/archives/2010/04/a_pixel_is_not.html