Flex 4.6 - 检测移动设备的屏幕尺寸 - systemManager.screen.width与Stage.width

时间:2011-12-13 03:09:22

标签: flex actionscript flex4 flash-builder flex4.5

对于移动Flex / Flash Builder,使用systemManager.screen.*Stage.*检测屏幕尺寸是否更好?为什么?

2 个答案:

答案 0 :(得分:5)

在大多数情况下,使用FlexGlobals.topLevelApplication.widthFlexGlobals.topLevelApplication.height更为可靠。

答案 1 :(得分:2)

在构建应用程序时,我认为知道我必须使用的空间比了解实际的屏幕尺寸更重要。

要获取此信息,我将绑定到Flex Framework并使用传递给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();

}