0
我想要根據各種平臺動態更改圖像的高度和寬度。加速器中平臺特定的高度和寬度
我檢查了appcelerator的platform.height和platform.width的文檔。但我似乎無法理解它是如何完成的。
我想要根據各種平臺動態更改圖像的高度和寬度。加速器中平臺特定的高度和寬度
我檢查了appcelerator的platform.height和platform.width的文檔。但我似乎無法理解它是如何完成的。
您可以使用此跨平臺代碼在dp中獲取寬度爲&的Android/iOS設備。
alloy.js
var df = Ti.Platform.displayCaps.logicalDensityFactor;
var w = OS_IOS ? Ti.Platform.displayCaps.platformWidth : Ti.Platform.displayCaps.platformWidth/df;
var h = OS_IOS ? Ti.Platform.displayCaps.platformHeight : Ti.Platform.displayCaps.platformHeight/df;
Alloy.Globals.deviceWidth = Math.min(w, h);
Alloy.Globals.deviceHeight = Math.max(w, h);
現在你可以在任何文件中使用這些全局變量你想是這樣的:
"#someLabel": {
width : Alloy.Globals.deviceWidth,
height : 100
}
究竟是什麼你想達到什麼樣的? –