我有一个布局,当它是纵向的时,它有总和规格。但是当我更改屏幕方向时,布局需要重新组织以适应整个屏幕。问题在于布局保持了他的尺寸。因此,如果布局开始纵向,I 更改为横向,则布局将保持纵向配置。如何制作布局,使其在屏幕方向更改时自动重新组织?
如何创建视图:
var deviceHeight = Ti.Platform.displayCaps.platformHeight,
deviceWidth = Ti.Platform.displayCaps.platformWidth,
platform = Ti.Platform.osname;
if (platform == 'android') {
deviceHeight = Math.round(Ti.Platform.displayCaps.platformHeight / Ti.Platform.displayCaps.logicalDensityFactor);
deviceWidth = Math.round(Ti.Platform.displayCaps.platformWidth / Ti.Platform.displayCaps.logicalDensityFactor);
}
var View = Ti.UI.createView({
height : deviceHeight,
width : deviceWidth,
backgroundColor : 'white',
layout : 'vertical'
});
非常重要:不要以点/像素为单位指定宽度,而要以百分比为单位。或者使用相对宽度。例如,如果想要一个全宽的视图,减去左边 10 个,右边减去 10 个,请指定:
Ti.UI.createView(){
left: 10,
right: 10
}
将应用程序视为不同的网站!让一切都是相对的。分辨率如此之多,不可能按分辨率进行布局。为移动设备制定单一解决方案,并可能为平板电脑重新安排一些内容。
如果确实要手动重绘,请使用此事件并在再次重定义所有视图后:
Ti.Gesture.addEventListener('orientationchange',function(e) {
});
为此,您需要保留对所有视图的引用并根据需要进行调整。