【发布时间】:2011-12-13 03:09:22
【问题描述】:
对于移动 Flex / Flash Builder,使用 systemManager.screen.* 或 Stage.* 检测屏幕尺寸是否更好 - 为什么?
【问题讨论】:
标签: apache-flex actionscript flex4 flash-builder flex4.5
对于移动 Flex / Flash Builder,使用 systemManager.screen.* 或 Stage.* 检测屏幕尺寸是否更好 - 为什么?
【问题讨论】:
标签: apache-flex actionscript flex4 flash-builder flex4.5
在大多数情况下,使用FlexGlobals.topLevelApplication.width 和FlexGlobals.topLevelApplication.height 更可靠。
【讨论】:
在构建应用程序时,我认为了解我必须使用的空间比了解实际的屏幕尺寸更重要。
要获取此信息,我将绑定到 Flex 框架并使用传递给 updateDisplayList() 方法的 unscaledWidth 和 unscaledHeight 属性。
问题是,为什么需要检测屏幕尺寸。如果您只需要使用它们来调整组件子组件的大小和位置,那么我相信我上面描述的解决方案是最好的解决方案。如果您出于其他原因需要此信息,请解释。
这是在其容器的 updateDisplayList 中调整标签大小和位置的一种方法:
protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
super.updateDisplayList(unscaledwidth, unscaledHeight);
// first position it
// you could also use this.myLabel.move(x,y) method to position the element
this.myLabel.x = 0;
this.myLabel.y = 0;
// then size it
// sizing to 100% height/width of container
this.myLabel.height = unscaledHeight;
this.myLabel.width = unscaledWidth;
// or you could also use setActualSize; which is slightly different than setting height and width
// becaues using setActualSize won't set the explicitHeight/explicitWidth, therefore measure will still
// execute
this.myLabel.setActualSize(unscaledWidth, unscaledHeight)
// or you could set the label to it's measured height and measured width
this.myLabel.height = this.myLabel.getExplicitOrMeasuredHeight();
this.myLabel.width = this.myLabel.getExplicitOrMeasuredWidth();
}
【讨论】:
updateDisplayList() 来定位组件的子级。对于多行文本(默认)labels,必须设置 width。按照网上的各种教程,我从舞台/屏幕宽度设置这个宽度 - 2*margin(假设它跨越了屏幕的可读宽度)。 updateDisplayList 在那里如何工作?