PhoneGap/Cordova Android在onDeviceReady之后获得屏幕尺寸

dym*_*ymv 11 android cordova

Android应用在onDeviceReady事件上返回无效大小(320x480),但几秒后大小变得正确.

我们怎样才能在一开始就获得正确的尺寸?或者是否有任何我可以获得正确尺寸的事件?

我正在使用此函数来获取大小:

function getWindowSizes() {
  var windowHeight = 0, windowWidth = 0;
  if (typeof (window.innerWidth) == 'number') {
      windowHeight = window.innerHeight;
      windowWidth = window.innerWidth;
      
  } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
      windowHeight = document.documentElement.clientHeight;
      windowWidth = document.documentElement.clientWidth;
      
  } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
     windowHeight = document.body.clientHeight;
     windowWidth = document.body.clientWidth;
  }
  return [windowWidth, windowHeight];
}
Run Code Online (Sandbox Code Playgroud)

视口:

<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />

使用Cordova 2.5.0.

UPD:
正如您在此屏幕截图中看到的那样,应用程序以较小的尺寸启动.即使是空的Cordova项目也是如此.我怎样才能解决这个问题?

在此输入图像描述

谢谢!

小智 3

删除元标头索引上的高度、宽度和密度属性。