Flex - 百分比高度

时间:2011-03-11 14:27:07

标签: flex actionscript-3 mxml

如何限制宽度/高度百分比为100%的子容器的大小?

示例:

<mx:HBox id="container" width="100%" height="100%">
    <mx:HBox id="scrollContainer" width="100%" height="100%">
        <!-- keep this content limited to the size of "container" -->
        <!-- I also want to use the scollers from "scrollContainer" -->
    </mx:HBox>
</mx:HBox>

现在“scrollContainer”中的内容一旦大于“容器”

就会溢出

修改

显然,如果我将HBox更改为Canvas,我可以获得所需的行为,但我仍然想知道如何使用HBox完成此操作以及它与Canvas的不同之处。

3 个答案:

答案 0 :(得分:0)

如果将外部HBox上的verticalScrollPolicy和horizo​​ntalScrollPolicy设置为“off”,则可以执行此操作。这是使用单个顶级HBox做得更好的事情 - 存在HBox,为您的控件提供水平布局,因此将一个嵌套在另一个100%内,可以为您提供两个嵌套级别,而不会产生任何功能差异。

使用Canvas的解决方案听起来比首先要求的布局更好,因为Canvas是一个更轻量级的控件,但如果你没有另一个,它仍然没有为你做任何事情那里的子控制。

答案 1 :(得分:0)

maxHeight,maxWidth属性

回答你的另一个问题。
画布 - 儿童对象X和Y的绝对定位设置为
HBox,VBox - 儿童定位基于父母(HBox,VBox) 使用HBox,VBox,如果你在孩子身上设置x或y,你会发现没有任何变化,父母会覆盖它。

答案 2 :(得分:0)

我认为你应该可以通过这样设置宽度来实现这个目的:

<mx:HBox id="container" width="100%" height="100%">
    <mx:HBox id="scrollContainer" width="{container.width}" height="{container.height}">
        <!-- keep this content limited to the size of "container" -->
        <!-- I also want to use the scollers from "scrollContainer" -->
    </mx:HBox>
</mx:HBox>
相关问题