在 Flex 移动应用程序中,我的应用程序组件处理组中的纵向/横向 ios/android 和手机/平板电脑等状态。在我的视图中,如果主应用程序具有这些特定状态,我想包含一个按钮。我不希望任何视图再次检查肖像/风景和东西以设置为自己的状态。另一方面,视图状态是其他事情所必需的。那么我怎么能说只有当 topLevelApplication 的状态是横向时才在我的视图中包含按钮呢?
1292 次
2 回答
2
使用属性 includein="landscape" 如果它以多个状态存在,您可以放置一个逗号分隔的列表
于 2012-02-27T19:04:56.893 回答
0
首先向您的应用程序添加两个状态:
<s:states>
<s:State name="portrait"/>
<s:State name="landscape"/>
</s:states>
接下来,将以下函数添加到您的<fx:Script>
部分:
<fx:Script>
<![CDATA[
import mx.events.ResizeEvent;
protected function application1_resizeHandler(event:ResizeEvent):void
{
if (width>height)
this.currentState="landscape";
else this.currentState="portrait";
}
]]>
</fx:Script>
在应用程序调整大小时也调用上面的方法:
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" applicationDPI="160" resize="application1_resizeHandler(event)">
现在,如果您想包含或排除一个组件,只需在所需组件上添加可见或includeIn :
visible.landscape="false"
或者
includeIn="landscape"
完整代码示例:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
resize="application1_resizeHandler(event)">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:states>
<s:State name="portrait"/>
<s:State name="landscape"/>
</s:states>
<fx:Script>
<![CDATA[
import mx.events.ResizeEvent;
protected function application1_resizeHandler(event:ResizeEvent):void
{
if (width>height)
this.currentState="landscape";
else this.currentState="portrait";
}
]]>
</fx:Script>
<s:Button includeIn="landscape" x="58" y="52" label="Landscape"/>
<s:Button includeIn="portrait" x="58" y="90" label="Portrait"/>
</s:WindowedApplication>
于 2012-04-02T13:46:08.897 回答