11

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];
}

视口:

<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" />

使用科尔多瓦 2.5.0。

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

在此处输入图像描述

谢谢!

4

3 回答 3

3

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

于 2013-03-29T14:47:29.720 回答
1

尝试删除标头中的 target-densitydpi。

设备 dpi 基于物理像素,而 css 像素是逻辑像素,它们有时彼此不同,如果你强制它们相同,你会看到屏幕被拉伸。

window.devicePixelRatio 可能会给你转换的结果。(在 webkit 上)

更新:

此链接提供了有关其工作原理的更多详细信息: https ://petelepage.com/blog/2013/02/viewport-target-densitydpi-support-is-being-deprecated/

于 2013-09-13T13:49:41.817 回答
0

尝试删除 app 类中的 position:absolute 属性(在 index.css 中)。这对我有用。

于 2013-09-05T10:10:35.597 回答