【问题标题】:Flex 4.6 - Detecting screen dimensions for mobile - systemManager.screen.width vs Stage.widthFlex 4.6 - 检测移动设备的屏幕尺寸 - systemManager.screen.width 与 Stage.width
【发布时间】:2011-12-13 03:09:22
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      要获取此信息,我将绑定到 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 在那里如何工作?
      • 我更新了我的答案,提供了一些关于如何在 updateDisplayList 中调整组件大小的示例代码。
      • 我想我仍然不明白的是你如何在运行时调整容器的大小?似乎这会因屏幕尺寸而异。
      • Flex 框架计算出这一点并将其作为函数参数传递给 updateDisplayList。
      • 仍然不清楚 Flex 是如何设置/获取容器宽度的。假设我设计了一个适合智能手机窄屏幕的多行标签。宽度的容器约束是 300 像素(大约是屏幕宽度的 80%),Flex 知道如何在 1000 像素的平板电脑屏幕宽度上将其缩放到 800 像素吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-21
      • 2013-06-28
      • 2015-05-11
      • 1970-01-01
      • 2017-11-12
      相关资源
      最近更新 更多