[英]Android detect rotation & screen width
I am trying to detect screen rotation in Webkit on my Motorola Droid 1. I have the following JavasCript code: 我正在尝试在Motorola Droid 1上的Webkit中检测屏幕旋转。我有以下JavasCript代码:
var supportsOrientationChange = "onorientationchange" in window,
orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
window.addEventListener(orientationEvent, function() {
alert("screen.width: " + screen.width + ", window.orientation: " + window.orientation);
}, false);
The problem is: it alerts screen.width 569 when the phone is rotated in portrait, and 320 when it is rotated in landscape. 问题是:当手机纵向旋转时,它会警告screen.width 569,横向旋转时会提示320。 This does not any sense to me!
这对我来说毫无意义! Can somebody clarify?
有人可以澄清吗?
Thank you, Igor 谢谢你,伊戈尔
I bet you are running Android 2.2. 我敢打赌,您正在运行Android 2.2。 There is a bug in the browser's reporting of width and height.
浏览器的宽度和高度报告中存在错误。 See screen.width + android and Shouldn't window.screen.width/height correspond to actual screen width/height?
请参阅screen.width + android , window.screen.width / height是否不对应于实际的屏幕宽度/高度? for starters.
对于初学者。
I wish I had something better to offer than the setTimeout()
workaround in that first post, but that may be the best you can do. 我希望我可以比第一篇文章中提供的
setTimeout()
解决方法更好的东西,但这可能是您可以做到的最好的方法。 (I'd love to be wrong about that, so if someone knows a better solution, please share!) (我很乐意对此表示错误,因此,如果有人知道更好的解决方案,请分享!)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.