需要更好地了解如何确定 Flex/Spark UI 元素的大小

发布于 2025-01-04 21:32:15 字数 1279 浏览 0 评论 0原文

总的来说,我还没有找到一种明确的方法来让 Flex 和 Spark 容器相对于子容器调整自身大小。我多次搜索过有关此概念的良好文档,但尚未找到任何足以解释这些概念的内容。

我经常想做的一个简单例子是在一组控件周围均匀地绘制边框。 这里的目标是让所有 UI 元素自动调整自身大小。

<s:BorderContainer>
  <s:HGroup>
    <s:Label text="l1" />
    <s:Label text="very long label 2" />
  </s:HGroup>
</s:BorderContainer>

我希望 Labels 根据 text 属性调整自身大小,并且 HGroup 应根据需要包含标签和 >BorderContainer 应该只包含该 HGroup


现在这个简单的例子可能会也可能不会按预期工作,我还没有弄清楚如何在不尝试代码的情况下确定输出的样子。 有谁知道理解这个过程的好方法,以便我可以确定地知道事情会是什么样子?


现在是我正在研究的更复杂的例子。 我有一个扩展 BorderContainer 的类。在类中,我创建了一个 HGroup,其中包含 5 个 Labels 作为 HGroup 的子级。然后将 HGroup 添加为 ExtendedBorderContainer 的子级(使用 addElement() 方法)。

然后新类在应用程序中使用如下:

<mx:ViewStack>
  <s:NavigatorContent>
    <my:ExtendedBorderContainer />
  </s:NavigatorContent>
  <!-- more NavigatorContents here -->
</mx:ViewStack>

我尝试了各种 [max|min]height/width 组合,但无法获得所需的布局,元素周围的边框非常紧密,没有多余的空间从最深的 Label 子项开始,一直到 NavigatorContent

In general, I haven't yet found a definitive way to get Flex and Spark containers to size themselves relative to their children. I have searched for good documentation for this concept many times but have yet to find anything that sufficiently explains the concepts.

A simple example of something I often want to do is to draw a border uniformly around a set of controls.
The goal here would be to have all UI elements to size themselves automatically.

<s:BorderContainer>
  <s:HGroup>
    <s:Label text="l1" />
    <s:Label text="very long label 2" />
  </s:HGroup>
</s:BorderContainer>

I would want the Labels to size themselves based on the text property, and the HGroup should be as big as needed to contain labels and BorderContainer should only just contain that HGroup.

Now this simple example may or may not work as desired, I haven't yet figured out how to determine what the output will look like without trying the code. Does anyone know of a good way to understand this process so I can know deterministically how things will look?


Now the more complicated example that I am working on now.
I have a class that extends the BorderContainer. Within the class I create an HGroup with 5 Labels as children of the HGroup. Then the HGroup is added as a child of the ExtendedBorderContainer (using addElement() method).

Then the new class is used in the application as:

<mx:ViewStack>
  <s:NavigatorContent>
    <my:ExtendedBorderContainer />
  </s:NavigatorContent>
  <!-- more NavigatorContents here -->
</mx:ViewStack>

I have tried various [max|min]height/width combinations and I can not get the desired layout, which is very tight borders around elements without extraneous space starting from the deepest Label children all the way up to the NavigatorContent.

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

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

发布评论

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

评论(1

末蓝 2025-01-11 21:32:15

看这里:
http://livedocs.adobe.com/flex/3 /html/help.html?content=size_position_3.html

目前尚不清楚您的问题是什么。
关于你的问题的第一部分:你所说的“可能会或可能不会按预期工作”是什么意思。该示例应该可以工作并且具有您所描述的布局。标签本身的大小基于文本属性等。你会得到什么行为?

第二部分:
如果您暗示您的布局总体上没问题,但项目之间有额外的间距,那么请查看容器的填充和间隙属性。某些容器具有非零的默认填充和间隙,您必须手动覆盖它们。

Look here:
http://livedocs.adobe.com/flex/3/html/help.html?content=size_position_3.html

It is not clear what your problem is.
Regarding first part of your question: what do you mean saying "may or may not work as desired". This example should work and have layout that you described. Label sizes itself based on text property and so on. What behaviour do you get?

Second part:
If you are hinting that your layout is ok in general but have extra spacing between items then look at the padding and gap properties of containers. Some containers have non zero default padding and gap and you have to override them manualy.

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