从右边填充一个HBox? VBox 从底部开始?
我真的只需要 HBox 答案,但我想如果我们在这里得到一个好的答案,它将帮助任何尝试使用 VBox 做类似事情的人。如果能在 ActionScript 和 MXML 中了解这一点就好了。
所以我有一个 HBox,我想要一些文本从左侧对齐,一些收音机从右侧对齐。像这样:
___________________________________________________
| |
|Text Yes () No() |
|___________________________________________________|
我目前正在通过在文本和收音机之间设置一个宽度为 100% 的隐形框来做到这一点,就像这样,
_____ __________________________________ ________________
| | | |
|Text | invisible box percentWidth=100; | Yes () No() |
|_____|__________________________________|________________|
我更愿意将收音机放在自己的 HBox 中,这样右对齐:
_____ ________________________________________________________
| | |
|Text | Yes () No() |
|_____|________________________________________________________|
我已经看到一些帖子讨论了 HorizontalAlign 属性,但我在任何地方的文档中都没有看到它。
那么我怎样才能做到这一点呢?
谢谢 〜迈克
I only really need the HBox answer but figure that if we get a good answer in here it would help anyone trying to do a similar thing with a VBox. It would be nice to know this in both actionscript and MXML.
So I have an HBox that I want some text aligned from the left and some radios from the right. Like so:
___________________________________________________
| |
|Text Yes () No() |
|___________________________________________________|
I am currently doing this by having an invisible box with a width of 100% between the text and the radios, like this
_____ __________________________________ ________________
| | | |
|Text | invisible box percentWidth=100; | Yes () No() |
|_____|__________________________________|________________|
I would prefer to just have the radios in their own HBox that is right aligned like this:
_____ ________________________________________________________
| | |
|Text | Yes () No() |
|_____|________________________________________________________|
I've seen some posts talk about a horizontalAlign property, but I don't see it in the documentation anywhere.
So how can I accomplish this?
Thanks
~mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
VBox 和 HBox 组件(继承自 Box)上有一个
horizontalAlign
属性和一个verticalAlign
属性。它们确定组件子组件的水平和垂直对齐方式。我通常使用 Spacer 对象,就像 Sam 提到的那样。但对于你想做的事情来说,这会很有用。
在 MXML 中,您可以执行以下操作:
请注意,具有水平对齐设置的 HBox 必须具有宽度值,否则,它的宽度将仅足以容纳其子项的宽度,在这种情况下对齐毫无意义。
这是一个 AS 版本:
There is a
horizontalAlign
property, and averticalAlign
property, on the VBox and HBox components (it's inherited from Box). They determine the horizontal and vertical alignment of the component's children.I generally use the Spacer object, like Sam mentions. But for what you want to do, this will work great.
In MXML you could do something like:
Note that the HBox with the
horizontalAlign
set has to have a width value, otherwise, it will only be wide enough to accommodate the width of its children, in which case alignment is moot.Here's an AS version:
如果您已经在布局中使用 HBox/VBox,那么使用 Spacer 是将某些项目一直移动到右侧/底部的正确方法。
另一种方法是基于约束的布局。当您想要将内容锚定到左侧时,这很好,您可以使用画布作为父级,并在子级上设置“right='0'”以将其一直定位到右侧。当您根据大小堆叠多个物品时,这不太理想。您可以使用绑定“right='{noComponent.width}”将 Yes 放在 No 的右侧。
If you're already using HBox/VBox for your layout, then using Spacer is the right way to go to move certain items all the way over to the right/bottom.
An alternative is constraint based layout. This is good when you want to anchor content to the left, you use a canvas as the parent and on the child set "right='0'" to position it all the way to the right. This is less ideal when you are stacking multiple items based on their size. You could use a binding, "right='{noComponent.width}" to put Yes just to the right of No.