Apache flex 如何使用数据绑定使容器保持与窗口相同的大小?

Apache flex 如何使用数据绑定使容器保持与窗口相同的大小?,apache-flex,actionscript,Apache Flex,Actionscript,这只是一个简单的例子,并不是我真正想要实现的。我想找到一个解决办法来处理这样的问题 我尝试了两种方法,但容器的大小有时与窗口的大小不同。我认为这可能是因为Flex的邀请验证模式 一,。 flash版本在我的chrome浏览器中正常工作。空气调节器没有我想象的那样工作。程序启动时,容器没有大小。其宽度和高度均为0。当我最大化窗口时,它仍然很小。当我最小化窗口时,它的大小变成全屏 <?xml version="1.0" encoding="utf-8"?> <s:WindowedA

这只是一个简单的例子,并不是我真正想要实现的。我想找到一个解决办法来处理这样的问题

我尝试了两种方法,但容器的大小有时与窗口的大小不同。我认为这可能是因为Flex的邀请验证模式

一,。 flash版本在我的chrome浏览器中正常工作。空气调节器没有我想象的那样工作。程序启动时,容器没有大小。其宽度和高度均为0。当我最大化窗口时,它仍然很小。当我最小化窗口时,它的大小变成全屏

<?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">

    <s:SkinnableContainer id="container" width="{width}" height="{height}"
                          backgroundColor="0x00FFFF"/>
</s:WindowedApplication>
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"
               creationComplete="application1_creationCompleteHandler(event)">

    <fx:Script>
        <![CDATA[
            import mx.binding.utils.BindingUtils;
            import mx.events.FlexEvent;
            import mx.utils.StringUtil;

            protected function application1_creationCompleteHandler(event:FlexEvent):void
            {
                setInterval(traceWidthAndHeight, 1000);

                BindingUtils.bindProperty(container, 'width', this, 'width');
                BindingUtils.bindProperty(container, 'height', this, 'height');
            }

            private function traceWidthAndHeight():void
            {
                trace(StringUtil.substitute('width: {0}, height: {1}\ncontainer.width: {2}, container.height: {3}',
                    width, height, container.width, container.height));
            }

        ]]>
    </fx:Script>

    <s:SkinnableContainer id="container"
                          backgroundColor="0x00FFFF"/>
</s:Application>
二,。 flash版本正常工作,而AIR版本则不正常。当我最大化窗口时,它仍然很小。当我最小化窗口时,它的大小变成全屏

<?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">

    <s:SkinnableContainer id="container" width="{width}" height="{height}"
                          backgroundColor="0x00FFFF"/>
</s:WindowedApplication>
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"
               creationComplete="application1_creationCompleteHandler(event)">

    <fx:Script>
        <![CDATA[
            import mx.binding.utils.BindingUtils;
            import mx.events.FlexEvent;
            import mx.utils.StringUtil;

            protected function application1_creationCompleteHandler(event:FlexEvent):void
            {
                setInterval(traceWidthAndHeight, 1000);

                BindingUtils.bindProperty(container, 'width', this, 'width');
                BindingUtils.bindProperty(container, 'height', this, 'height');
            }

            private function traceWidthAndHeight():void
            {
                trace(StringUtil.substitute('width: {0}, height: {1}\ncontainer.width: {2}, container.height: {3}',
                    width, height, container.width, container.height));
            }

        ]]>
    </fx:Script>

    <s:SkinnableContainer id="container"
                          backgroundColor="0x00FFFF"/>
</s:Application>

我知道100%的宽度和高度可以达到我的目标。但是,我想知道是否可以使用数据绑定来完成。提前感谢。

解决方案是使用布局,因此在窗口上设置垂直或水平布局,然后将容器宽度和高度设置为100%

示例mxml

<?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">
    <s:layout>
        <s:VerticalLayout paddingBottom="12" paddingLeft="12" paddingRight="12" paddingTop="12"/>
    </s:layout>
<s:BorderContainer width="100%" height="100%" borderColor="blue"/>
</s:WindowedApplication>

或者,使用默认的基本布局,可以指定左/右/上/下的约束。