Apache flex 当子容器';s的可见性改变了吗?

Apache flex 当子容器';s的可见性改变了吗?,apache-flex,resize,scroll,hide,visible,Apache Flex,Resize,Scroll,Hide,Visible,当我为容器中的子容器将visible属性设置为false时,如何调整容器的大小?在下面的示例中,当单击“切换”时,“containerB”被隐藏,但主容器的可滚动区域没有调整大小。(我不想在很多空白处滚动。) 从很多方面来看,我认为考虑到您当前的代码,您应该收听containerB上的show and hide事件 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="creationCo

当我为容器中的子容器将visible属性设置为false时,如何调整容器的大小?在下面的示例中,当单击“切换”时,“containerB”被隐藏,但主容器的可滚动区域没有调整大小。(我不想在很多空白处滚动。)



从很多方面来看,我认为考虑到您当前的代码,您应该收听containerB上的show and hide事件

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="creationComplete()">
<mx:Script>
    <![CDATA[
        public function toggle():void {
            containerB.visible = !containerB.visible;
        }
public function creationComplete():void{
 containerB.addEventListener(FlexEvent.SHOW, onContainerBChange );
 containerB.addEventListener(FlexEvent.HIDE, onContainerBChange );
}
public function onContainerBChange():void{
if(this.containerB.visible == true){
this.mainContainer.width = this.containerB.width + this.containerA.width
this.mainContainer.height = this.containerB.height + this.containerA.height
} else {
 this.mainContainer.width = this.containerA.width;
this.mainCintainer.height = this.containerA.height;
}
}

    ]]>
</mx:Script>
<mx:VBox height="300" width="200" horizontalAlign="center" id="mainContainer">
    <mx:Button label="Toggle" click="toggle()" width="200"/>
    <mx:VBox id="containerA" height="400" width="150" horizontalAlign="center">
        <mx:Button label="A" height="400" width="100"/>
    </mx:VBox>
    <mx:VBox id="containerB" height="400" width="150" horizontalAlign="center">
        <mx:Button label="B" height="400" width="100"/>         
    </mx:VBox>
</mx:VBox>

我正在浏览器中编写代码,因此应将其视为psuedo代码。如果您不在OnContainerChange处理程序中使用调整大小代码,而是使displaylist无效,并将代码放入updateDisplayList()中,那么这对您来说是一个很大的好处

作为一个完整的旁白;我希望您真正的代码不会使用VBox,其中只有一个容器。在这个简单的示例中,没有理由不将containerA和containerB一起删除,而只在VBox中使用三个按钮


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
    <![CDATA[
        public function toggle():void {
            containerB.visible = !containerB.visible;
        }
    ]]>
</mx:Script>
<mx:VBox height="300" width="200" horizontalAlign="center">
    <mx:Button label="Toggle" click="toggle()" width="200"/>
    <mx:VBox id="containerA" height="400" width="150" horizontalAlign="center">
        <mx:Button label="A" height="400" width="100"/>
    </mx:VBox>
    <mx:VBox id="containerB" height="400" width="150" horizontalAlign="center" includeInLayout="{containerB.visible}">
        <mx:Button label="B" height="400" width="100"/>         
    </mx:VBox>
</mx:VBox>
</mx:Application>
您好,只需使containerB includeInLayout属性依赖于其可见属性

我刚刚在conatinerB属性列表中添加了includeInLayout=“{containerB.visible}”,这是有效的,我希望这是您所期待的

玩个痛快

安库尔·夏尔马

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
    <![CDATA[
        public function toggle():void {
            containerB.visible = !containerB.visible;
        }
    ]]>
</mx:Script>
<mx:VBox height="300" width="200" horizontalAlign="center">
    <mx:Button label="Toggle" click="toggle()" width="200"/>
    <mx:VBox id="containerA" height="400" width="150" horizontalAlign="center">
        <mx:Button label="A" height="400" width="100"/>
    </mx:VBox>
    <mx:VBox id="containerB" height="400" width="150" horizontalAlign="center" includeInLayout="{containerB.visible}">
        <mx:Button label="B" height="400" width="100"/>         
    </mx:VBox>
</mx:VBox>
</mx:Application>