【问题标题】:Container that fills up parent container填满父容器的容器
【发布时间】:2014-06-03 10:53:25
【问题描述】:

我有一个容器,它的高度可以在运行时改变。顶部有一些固定高度的项目,底部有一些固定高度的项目,我想在它们之间有一个容器来填充剩余空间。

这是我目前拥有的 mxml 的提炼。我希望 contentContainer 自动调整大小。 compA 和 compB 是实际实现中的 mxml 组件,因此它们的结构(尽管不一定是容器类型)需要保持完整。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%">
    <mx:VBox width="500" height="500" id="compA">
        <mx:VBox width="100%" id="compB">
            <mx:HBox width="100%">
                <mx:Label text="Header" />
            </mx:HBox>

            <mx:VBox id="contentContainer" width="100%" height="100%">
                <mx:Canvas verticalScrollPolicy="on" width="100%" height="100%">
                    <mx:VBox width="100%" height="100%">
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                        <mx:Label text="Content" />
                    </mx:VBox>
                </mx:Canvas>
            </mx:VBox>
        </mx:VBox>
        <mx:HBox width="100%">
            <mx:Label text="Footer" />
        </mx:HBox>
    </mx:VBox>
</mx:Application>

【问题讨论】:

    标签: apache-flex flex3 mxml


    【解决方案1】:

    您可以通过在它们上设置显式heights 并指定topbottom 参数来将页眉和页脚锚定到屏幕的顶部和底部。然后将主要内容VBoxtopbottom参数设置为与页眉页脚相同的值:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%">
        <mx:HBox top="0" height="50">
            <mx:Label text="Header" />
        </mx:HBox>
        <mx:VBox id="contentContainer" width="100%" top="50" bottom="50">
            <mx:Canvas verticalScrollPolicy="on" width="100%" height="100%">
                <mx:VBox width="100%" height="100%">
                    <mx:Label text="Content" />
                                        <!-- etc... -->
                    <mx:Label text="Content" />
                </mx:VBox>
            </mx:Canvas>
        </mx:VBox>
        <mx:HBox width="100%" bottom="0" height="50">
            <mx:Label text="Footer" />
        </mx:HBox>
    </mx:Application>
    

    【讨论】:

    • 啊,顶部和底部,回想起来很明显。不幸的是,在实际应用程序中,需要维护一个组件结构(我已经更新了问题以反映这一点),但我无法让它与它一起工作。我希望我只需要更改组件的根容器类型,但我不知道该怎么做。
    • 可以在页眉和页脚设置固定高度吗?除非您必须在 compA 上保持固定尺寸,否则这应该可行
    猜你喜欢
    • 2020-07-05
    • 2018-04-22
    • 2019-05-19
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    • 2014-06-24
    • 1970-01-01
    • 2013-09-02
    相关资源
    最近更新 更多