简体   繁体   English

JavaScript + Phonegap + Android:screen.width返回糟糕(几乎随机)的值

[英]JavaScript+Phonegap+Android: screen.width returns bad (almost random) values

After launching app with "deviceready" event, my Phonegap app on Android returns false screen.width (window.innerWidth is the same) values on ZTE Blade (native 800px). 使用“deviceready”事件启动应用程序后,Android上的Phonegap应用程序在ZTE Blade(本机800px)上返回false screen.width(window.innerWidth相同)值。 I get width values like 320, 533 or 787 px, sometimes different values within one app instance (launch) when asking multiple times... 我得到宽度值,如320,533或787像素,有时在一个应用程序实例(启动)中有多个不同的值,当多次询问时......

I have android:screenOrientation="landscape" in my AndroidManifest.xml. 我的AndroidManifest.xml中有android:screenOrientation =“landscape”。 Using Phonegap/Cordova 1.8.1 in Eclipse (Indigo). 在Eclipse(Indigo)中使用Phonegap / Cordova 1.8.1。

Some sample values of screen.width: screen.width的一些示例值:

in index.html 在index.html中

  • before document.addEventListener+"deviceready": 320 在document.addEventListener +“deviceready”之前:320
  • just after "deviceready": 320 就在“deviceready”之后:320

then redirect three times (change window.location to different HTML file) because of 2 splash-screens and finally land to main.html. 然后重定向三次(将window.location更改为不同的HTML文件),因为2个启动屏幕,最后登陆到main.html。 I include my .js code in every file just for debugging, and get 3 console.logs: 我将.js代码包含在每个文件中仅用于调试,并获得3个console.logs:

  1. 320 320
  2. 787 787
  3. 787 787

Very strange... 很奇怪...

There's a comprehensive article (+ comparison tables of different values) that you should read: http://tripleodeon.com/2011/12/first-understand-your-screen/ 你应该阅读一篇全面的文章(+不同值的比较表): http//tripleodeon.com/2011/12/first-understand-your-screen/

Hope this helps with your issue. 希望这有助于解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM