当孩子的可见性改变时调整容器的大小?

发布于 2024-09-02 22:29:42 字数 881 浏览 8 评论 0原文

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

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<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">
        <mx:Button label="B" height="400" width="100"/>         
    </mx:VBox>
</mx:VBox>

When I set the visible property to false for a child in a container, how can I get the container to resize? In the example bellow, when clicking on "Toggle", "containerB" is hidden, but the main container's scrollable area is not resized. (I do not want to scroll through a lot of empty space.)

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<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">
        <mx:Button label="B" height="400" width="100"/>         
    </mx:VBox>
</mx:VBox>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半透明的墙 2024-09-09 22:29:42
<?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属性依赖于它的visible属性,

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

有一个gr8时间

的原因安库尔·夏尔马

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

Hi, just make the containerB includeInLayout property to be dependant on its visible property,

i just added includeInLayout="{containerB.visible}" in conatinerB property list, this is working, i hope this is wht u were luking for

have a gr8 time

Ankur Sharma

东走西顾 2024-09-09 22:29:42

有很多方法,我认为考虑到您当前的代码,您应该监听 containerB 上的显示和隐藏事件。

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

我正在浏览器中编写代码,因此这应该被视为伪代码。如果您不用在 onContainerBChange 处理程序中使用调整大小代码,而是使显示列表无效并将代码放入 updateDisplayList() 中,那么这对您来说是一个很大的优势;

作为一个完整的旁白;我希望你的真实代码不使用内部只有一个容器的 VBox。在这个简单的示例中,您没有理由不能完全消除容器 A 和容器 B,而在 VBox 中只包含三个按钮。

Lots of ways, I think given your current code you should listen to the show and hide event on containerB.

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

I'm writing code in the browser so this should viewed as psuedo code. A big plus for you if, instead of having the resize code in the onContainerBChange handler you invalidate the displaylist and put the code in updateDisplayList();

As a complete aside; I hope your real code does not use a VBox with only a container inside it. In this simple example, there is no reason you can't have eliminate containerA and containerB altogether and just have three buttons in an VBox.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文