1

如果您运行以下 mxml 代码,您将看到位于第二行MyLabel1的其他标签(例如)和其他项目的上方。MyLabel2

如何更改代码以使其MyLabel1MyLabel2等一致?

请注意,任何更改都需要保持 、 和 的组MyLabel2MyLabel3(左侧)和(右侧)MyButton3之间等距,就像现在一样。换句话说,第 2 行的中间组不在容器的中心,但在它的左侧和右侧具有相等的空间。MyLabel1MyLabel4

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" 
           minWidth="200" minHeight="300">

<s:VGroup top="10" left="20" right="20">

    <s:Group width="100%">

        <s:HGroup left="0" top="5" verticalAlign="baseline">
            <s:Label text="Some Text Here" />
        </s:HGroup>

        <s:HGroup right="0" verticalAlign="baseline">
            <s:Button label="Button1" width="65"/>
            <s:Button label="Button2" width="65"/>
        </s:HGroup>

    </s:Group> 

    <s:Spacer height="2"/>

    <s:HGroup width="100%" >

        <s:HGroup >
            <s:Label text="MyLabel1"/>
        </s:HGroup>

        <s:Spacer width="100%"/> 

        <s:HGroup verticalAlign="baseline">
            <s:Label text="MyLabel2"/>
            <s:Label text="MyLabel3"/>
            <s:Button label="MyButton3" width="85"/>            
        </s:HGroup>

        <s:Spacer width="100%"/>

        <s:HGroup verticalAlign="baseline">
            <s:Label text="MyLabel4"/>
            <s:TextInput id="myID" />  
        </s:HGroup>

    </s:HGroup>

</s:VGroup> 

4

2 回答 2

1

尝试:

将三个 hgroup verticalAlign 设置为 middle 以便包含的项目位于组件高度的中间...

那么您需要为三个 hgroup 指定一个高度,因为: - 第一个只有一个标签(具有一定高度) - 在其他两个中,有一个按钮和一个文本输入,其高度大于简单标签(组 1)

使用组的自定义高度覆盖内部组件设置的高度

<s:VGroup top="10" left="20" right="20">

    <s:Group width="100%">

        <s:HGroup left="0" top="5" verticalAlign="baseline">
            <s:Label text="Some Text Here" />
        </s:HGroup>

        <s:HGroup right="0" verticalAlign="baseline">
            <s:Button label="Button1" width="65"/>
            <s:Button label="Button2" width="65"/>
        </s:HGroup>

    </s:Group> 

    <s:Spacer height="2"/>

    <s:HGroup width="100%" >

        <s:HGroup verticalAlign="middle" height="25">
            <s:Label text="MyLabel1"/>
        </s:HGroup>

        <s:Spacer width="100%"/> 

        <s:HGroup verticalAlign="middle" height="25">
            <s:Label text="MyLabel2"/>
            <s:Label text="MyLabel3"/>
            <s:Button label="MyButton3" width="85"/>            
        </s:HGroup>

        <s:Spacer width="100%"/>

        <s:HGroup verticalAlign="middle" height="25">
            <s:Label text="MyLabel4"/>
            <s:TextInput id="myID" />  
        </s:HGroup>

    </s:HGroup>

</s:VGroup> 
于 2012-05-02T08:26:54.077 回答
1

只需将verticalAlign="baseline" 添加到最外部的HGroup。

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

        <s:VGroup top="10" left="20" right="20">

            <s:Group width="100%">

                <s:HGroup left="0" top="5" verticalAlign="baseline">
                    <s:Label text="Some Text Here" />
                </s:HGroup>

                <s:HGroup right="0" verticalAlign="baseline">
                    <s:Button label="Button1" width="65"/>
                    <s:Button label="Button2" width="65"/>
                </s:HGroup>

            </s:Group> 

            <s:Spacer height="2"/>

            <s:HGroup width="100%" verticalAlign="baseline" >

                <s:HGroup>
                    <s:Label text="MyLabel1"/>
                </s:HGroup>

                <s:Spacer width="100%"/> 

                <s:HGroup verticalAlign="baseline">
                    <s:Label text="MyLabel2"/>
                    <s:Label text="MyLabel3"/>
                    <s:Button label="MyButton3" width="85"/>            
                </s:HGroup>

                <s:Spacer width="100%"/>

                <s:HGroup verticalAlign="baseline">
                    <s:Label text="MyLabel4"/>
                    <s:TextInput id="myID" />  
                </s:HGroup>

            </s:HGroup>

        </s:VGroup>     

</s:Application>
于 2012-05-02T11:59:24.463 回答