在 Flex 中调整容器大小以仅遵守父容器的显式尺寸的最佳方法 [英] Best way to size containers in Flex to obey ONLY parent containers' explicit dimensions

查看:27
本文介绍了在 Flex 中调整容器大小以仅遵守父容器的显式尺寸的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

近一年来,我一直在使用 Flex 遇到这个问题,每次我都想出一个暂时有效的快速破解解决方案.我想看看是否有人有更好的主意.

I've been running into this problem with Flex for nearly a year, and each time I work up a quick hack solution that works for the time being. I'd like to see if anyone has a better idea.

以下是问题的条件:

|------Container  ------------|
|  explicitHeight:  400 (or whatever)
|                             |
|  |-------- VBox  -------|   |
|  |  percentHeight: 100  |   | 
|  |                      |   |
|  |  |-Repeater------|   |   |
|  |  | Potentially   |   |   |
|  |  | a lot of stuff.   |   |
|--|--|---------------|---|---|

问题在于,与我希望发生的情况相反,VBox 将始终扩展以容纳其中的内容,而不是坚持其父项的显式高度并创建滚动条.

The problem is that, contrary to what I would like to happen, the VBox will ALWAYS expand to accommodate the content inside it, instead of sticking to the explicit height of its parent and creating a scroll bar.

我的解决方案是在对父项的引用中进行硬编码(或者我们需要在显示列表中找到一个明确设置的值而不是百分比).

My solution has been to hard code in a reference to the parent (or however far up the display list we need to go to find an explicitly set value as opposed to a percentage).

我什至考虑在实用程序类中使用它:

I've even considered using this in a utility class:

public static function getFirstExplicitHeightInDisplayList(comp:UIComponent):Number{
    if (!isNaN(comp.explicitHeight)) return comp.explicitHeight;
    if (comp.parent is UIComponent) return    
         getFirstExplicitHeightInDisplayList(UIComponent(comp.parent));
    else return 0;
}

请告诉我有更好的方法.

Please tell me there's a better way.

推荐答案

您必须在 VBox 上使用autoLayout"参数,如文档所述:

"默认情况下,VBox 容器的大小足以容纳图像的原始大小.如果禁用布局更新,并使用缩放效果放大图像,或使用移动效果重新定位图像,图像可能会超出 VBox 容器的边界.

您将 autoLayout 属性设置为 false,因此 VBox 容器不会在图像调整大小时调整大小.如果图像增大到超出 VBox 容器边界的大小,容器会添加滚动条并在其边界处剪切图像.

You have to use the "autoLayout" parameter on the VBox as documentation say:

"By default, the size of the VBox container is big enough to hold the image at it original size. If you disable layout updates, and use the Zoom effect to enlarge the image, or use the Move effect to reposition the image, the image might extend past the boundaries of the VBox container.

You set the autoLayout property to false, so the VBox container does not resize as the image resizes. If the image grows to a size so that it extends beyond the boundaries of the VBox container, the container adds scroll bars and clips the image at its boundaries.

希望能帮到你.

这篇关于在 Flex 中调整容器大小以仅遵守父容器的显式尺寸的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆