从右边填充一个HBox? VBox 从底部开始?

发布于 2024-08-19 05:48:49 字数 1129 浏览 3 评论 0原文

我真的只需要 HBox 答案,但我想如果我们在这里得到一个好的答案,它将帮助任何尝试使用 VBox 做类似事情的人。如果能在 ActionScript 和 MXML 中了解这一点就好了。

所以我有一个 HBox,我想要一些文本从左侧对齐,一些收音机从右侧对齐。像这样:

 ___________________________________________________
|                                                   |
|Text                                Yes ()  No()   |
|___________________________________________________|

我目前正在通过在文本和收音机之间设置一个宽度为 100% 的隐形框来做到这一点,就像这样,

 _____ __________________________________ ________________
|     |                                  |                |
|Text | invisible box  percentWidth=100; | Yes ()  No()   |
|_____|__________________________________|________________|

我更愿意将收音机放在自己的 HBox 中,这样右对齐:

 _____ ________________________________________________________
|     |                                                        |
|Text |                                         Yes ()  No()   |
|_____|________________________________________________________|

我已经看到一些帖子讨论了 Horizo​​ntalAlign 属性,但我在任何地方的文档中都没有看到它。

那么我怎样才能做到这一点呢?

谢谢 〜迈克

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 技术交流群。

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

发布评论

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

评论(2

宣告ˉ结束 2024-08-26 05:48:49

VBox 和 HBox 组件(继承自 Box)上有一个 horizo​​ntalAlign 属性和一个 verticalAlign 属性。它们确定组件子组件的水平和垂直对齐方式。

我通常使用 Spacer 对象,就像 Sam 提到的那样。但对于你想做的事情来说,这会很有用。

在 MXML 中,您可以执行以下操作:

<mx:RadioButtonGroup id="yesNoRadioGroup"/>

<mx:HBox id="containingHBox" width="100%">
    <mx:Text id="textElement" width="200" text="lakdfa lkadslkjraklnd kadflk lakdsjlkja lksdlkjdflk jalkdlkjdfslksajdf lkjasdflkjdsalkjds lksdjlkj"/>
    <mx:HBox id="rightAlignedHorizontalContent" width="100%" horizontalAlign="right">
        <mx:RadioButton id="yesRadio" label="Yes" groupName="yesNoRadioGroup"/>
        <mx:RadioButton id="noRadio" label="No" groupName ="yesNoRadioGroup"/>
    </mx:HBox>
</mx:HBox>

请注意,具有水平对齐设置的 HBox 必须具有宽度值,否则,它的宽度将仅足以容纳其子项的宽度,在这种情况下对齐毫无意义。

这是一个 AS 版本:

<mx:Script>
    <![CDATA[
        import mx.controls.RadioButton;
        import mx.controls.RadioButtonGroup;
        import mx.controls.Text;

        private var containingHBox:HBox;
        private var textElement:Text;
        private var rightAlignedHorizontalContent:HBox;
        private var yesNoRadioGroup:RadioButtonGroup; 
        private var yesRadio:RadioButton;
        private var noRadio:RadioButton;

        override protected function createChildren():void
        {
            super.createChildren();

            containingHBox = new HBox();
            containingHBox.percentWidth = 100;

            textElement = new Text();
            textElement.width = 200;
            textElement.text = "lakdfa lkadslkjraklnd kadflk lakdsjlkja lksdlkjdflk jalkdlkjdfslksajdf lkjasdflkjdsalkjds lksdjlkj";

            rightAlignedHorizontalContent = new HBox();
            rightAlignedHorizontalContent.percentWidth = 100;
            rightAlignedHorizontalContent.setStyle("horizontalAlign","right");

            yesNoRadioGroup = new RadioButtonGroup();

            yesRadio = new RadioButton();
            yesRadio.label = "Yes";
            yesRadio.groupName = "yesNoRadioGroup";

            noRadio = new RadioButton();
            noRadio.label = "No";
            noRadio.groupName = "yesNoRadioGroup";


            addChild(containingHBox);

            containingHBox.addChild(textElement);
            containingHBox.addChild(rightAlignedHorizontalContent);

            rightAlignedHorizontalContent.addChild(yesRadio);
            rightAlignedHorizontalContent.addChild(noRadio);
        }
    ]]>
</mx:Script>

There is a horizontalAlign property, and a verticalAlign 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:

<mx:RadioButtonGroup id="yesNoRadioGroup"/>

<mx:HBox id="containingHBox" width="100%">
    <mx:Text id="textElement" width="200" text="lakdfa lkadslkjraklnd kadflk lakdsjlkja lksdlkjdflk jalkdlkjdfslksajdf lkjasdflkjdsalkjds lksdjlkj"/>
    <mx:HBox id="rightAlignedHorizontalContent" width="100%" horizontalAlign="right">
        <mx:RadioButton id="yesRadio" label="Yes" groupName="yesNoRadioGroup"/>
        <mx:RadioButton id="noRadio" label="No" groupName ="yesNoRadioGroup"/>
    </mx:HBox>
</mx:HBox>

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:

<mx:Script>
    <![CDATA[
        import mx.controls.RadioButton;
        import mx.controls.RadioButtonGroup;
        import mx.controls.Text;

        private var containingHBox:HBox;
        private var textElement:Text;
        private var rightAlignedHorizontalContent:HBox;
        private var yesNoRadioGroup:RadioButtonGroup; 
        private var yesRadio:RadioButton;
        private var noRadio:RadioButton;

        override protected function createChildren():void
        {
            super.createChildren();

            containingHBox = new HBox();
            containingHBox.percentWidth = 100;

            textElement = new Text();
            textElement.width = 200;
            textElement.text = "lakdfa lkadslkjraklnd kadflk lakdsjlkja lksdlkjdflk jalkdlkjdfslksajdf lkjasdflkjdsalkjds lksdjlkj";

            rightAlignedHorizontalContent = new HBox();
            rightAlignedHorizontalContent.percentWidth = 100;
            rightAlignedHorizontalContent.setStyle("horizontalAlign","right");

            yesNoRadioGroup = new RadioButtonGroup();

            yesRadio = new RadioButton();
            yesRadio.label = "Yes";
            yesRadio.groupName = "yesNoRadioGroup";

            noRadio = new RadioButton();
            noRadio.label = "No";
            noRadio.groupName = "yesNoRadioGroup";


            addChild(containingHBox);

            containingHBox.addChild(textElement);
            containingHBox.addChild(rightAlignedHorizontalContent);

            rightAlignedHorizontalContent.addChild(yesRadio);
            rightAlignedHorizontalContent.addChild(noRadio);
        }
    ]]>
</mx:Script>
何以笙箫默 2024-08-26 05:48:49

如果您已经在布局中使用 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.

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