Flex formitem label aligment oddity

ε祈祈猫儿з 提交于 2020-01-02 07:20:16

问题


I have paid a decent hair tribute to this one
Why in the world, Label 1 and Label 2 have different vertical alignments?

        <s:Form width="100%">
            <s:FormHeading width="100%" label="Heading" />
            <s:FormItem width="100%" label="Label 1">
                <s:HGroup verticalAlign="bottom">
                    <s:Label text="Size" fontSize="40"/>
                    <s:Label text="Mb"/>                        
                </s:HGroup>
            </s:FormItem>
            <s:FormItem width="100%" label="Label 2">
                <s:HGroup verticalAlign="middle">
                    <s:VGroup horizontalAlign="center">
                        <s:Label text="Set1" />
                        <s:Label text="{this.set1}" fontSize="40"/>
                        <s:Label text="Days" />
                    </s:VGroup>
                    <s:Label text="+" fontSize="40" />
                    <s:VGroup horizontalAlign="center">
                        <s:Label text="Set2" />
                        <s:Label text="{this.set2}" fontSize="40" />
                        <s:Label text="Days" />
                    </s:VGroup>
                </s:HGroup>
            </s:FormItem>
        </s:Form>

回答1:


Bug or feature? The label of a FormItem is aligned with the baseline of the FormItem's content. A picture says more than a thousand words, so I'll show you what happens:

So it turns out to be a feature (thanks for asking this question: I didn't know this myself until today).

In order to "fix" this feature, you'll have to create a custom skin: create a skin class by copying the original spark.skins.spark.FormItemSkin.
Find the element called labelDisplay; it should look like this:

<s:Label id="labelDisplay"
         fontWeight="bold"
         left="labelCol:0" right="labelCol:5" 
         bottom="row1:10" baseline="row1:0"/>  

See that baseline attribute? That's what's causing the undesired behaviour.
You can simply remove it; the label will then always align to the bottom. If you wish to align it to the vertical center, you could alter it like this:

<s:Label id="labelDisplay" fontWeight="bold" verticalAlign="middle"
         left="labelCol:0" right="labelCol:5" top="row1:10" bottom="row1:10"/>

Now all you need to do, is applying your custom skin to your FormItem:

<s:FormItem skinClass="my.custom.FormItemSkin">

Or in case of more frequent usage:

<fx:Style>
    @namespace s "library://ns.adobe.com/flex/spark";

    s|FormItem.centeredLabel {
        skinClass: ClassReference("my.custom.FormItemSkin");
    }
</fx:Style>

<s:FormItem styleName="centeredLabel">


来源:https://stackoverflow.com/questions/13361699/flex-formitem-label-aligment-oddity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!