【问题标题】:Flex 4 - Vertical layout problem on TitleWindowFlex 4 - TitleWindow 上的垂直布局问题
【发布时间】:2025-11-25 14:40:01
【问题描述】:

这一定是一个简单的问题,但我无法理解它。我有一个可调整大小的标题窗口。在里面我只想要一个 VGroup 来保存表单的内容,一个 HGroup 在底部有几个按钮。非常标准的东西。

<!-- Content -->
<s:VGroup id="content" height="340" width="100%">
        ...more stuff in here...
</s:VGroup>


<!-- Buttons -->
<s:HGroup id="buttonGroup" width="100%"> 
    ...buttons in here...
</s:HGroup> 

水平调整大小可以正常工作。但是,我希望它的行为使得当 TitleWindow 垂直调整大小时,按钮相对于 TitleWindow 保持在同一位置,并且内容 VGroup 垂直调整大小。但是我不知道将 VGroup 的高度设置为什么?

理想情况下应该是这样的:

height="{this.parent.height - buttonGroup.height - top*

或者类似的......

【问题讨论】:

    标签: user-interface flex4 mxml


    【解决方案1】:

    使用约束属性。 你可以试试 AS:

    content.top = 0;  
    content.bottom = buttonGroup.height;  
    buttonGroup.bottom = 0;  
    

    但最好把它放到MXML中定义组件

    <s:VGroup id="content" top="0" bottom="{buttonGroup.height}" width="100%">
            ...more stuff in here...
    </s:VGroup>
    <s:HGroup id="buttonGroup" bottom="0" width="100%"> 
        ...buttons in here...
    </s:HGroup> 
    

    如果你喜欢,可以添加一些填充和边距

    【讨论】:

    • 谢谢——这适用于 BasicLayout,但我忘了提到我正在尝试使用 VerticalLayout。我不知道我为什么这么纠结……要多睡觉!
    • @Deshene 这肯定行得通。我唯一不喜欢的是数据绑定。如果您尝试使用 CSS 修复此布局,您将无法设置底部。
    【解决方案2】:

    您还可以尝试以下技巧:

    <s:VGroup id="layoutContainer" width="100%" height="100%">
    
        <s:SkinnableContainer id="content" height="100%">
            ....content here....
        </s:SkinnableContainer>
    
        <!-- Buttons -->
        <s:HGroup id="buttonGroup"> 
            ... buttons here...
        </s:HGroup>
    </s:VGroup>
    

    目的是使内容容器在 VGroup 中占据尽可能多的垂直空间。

    如果这对你有用,请告诉我!

    【讨论】:

    • 与 VerticalLayout 一起工作的圣牛!我真的没想到,我不明白。我原以为将高度设置为 100% 会占用整个容器并且事情会重叠,但我想 VGroup 行为比我想的更好编程。无论如何,你是我的英雄……谢谢。
    最近更新 更多