使用ConstraintLayout创建复杂的表单布局

原文地址: Flex – Complex Form layouts with ContraintLayout

Form容器默认使用FormLayout布局排列子表单项。FormLayout继承自VerticalLayout,它对FormItem容器进行纵向排列。如果你想实现纵向的排列表单,这当然好,但是很多时候往往不是这样。看看下面的例子。

通常情况下,我看到开发者在实现一个表单布局的时候,会放弃FormLayout布局而是使用一堆嵌套的HGroup和VGroup,尽管这种做法有点傻X,效果也不太理想。

还记得Flex 3中的ConstraintRows和ConstraintColumns么?它们在Flex 4中换了个ConstraintLayout的马甲又出现了,这个Layout可以用在Form中。我发现许多Flex开发者不知道这件事,这不奇怪,因为它们在官方文档中的说明少得可怜。而且,如果使用Google搜索它,你只能得到MX组件的相关内容。

上面的表单在Spark Form容器中使用ConstraintLayout替代了FormLayout,这个Layout为FormItem容器提供了类似于网格布局的功能,同时实现跨行、跨列。

? View Code XML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?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"
               viewSourceURL="srcview/index.html">
    <s:layout>
        <s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/>
    </s:layout>
 
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
 
    <s:Form>
        <s:layout>
            <s:ConstraintLayout>
                <s:constraintRows>
                    <s:ConstraintRow id="row1" />
                    <s:ConstraintRow id="row2"/>
                    <s:ConstraintRow id="row3"/>
                </s:constraintRows>
                <s:constraintColumns>
                    <s:ConstraintColumn id="col1" width="100"/>
                    <s:ConstraintColumn id="col2" width="100"/>
                    <s:ConstraintColumn id="col3" width="100"/>
                </s:constraintColumns>
            </s:ConstraintLayout>
        </s:layout>
 
        <s:FormItem label="First Name"
                    left="col1:3" right="col2:53" top="row1:0" bottom="row1:0"
                    skinClass="com.shinynet.shinylib.skins.CondensedStackedFormItemSkin">
            <s:TextInput width="100%"/>
        </s:FormItem>
        <s:FormItem label="Last Name"
                    left="col2:53" right="col3:3" top="row1:0" bottom="row1:0"
                    skinClass="com.shinynet.shinylib.skins.CondensedStackedFormItemSkin">
            <s:TextInput width="100%"/>
        </s:FormItem>
 
        <s:FormItem label="Address"
                    left="col1:3" right="col3:3" top="row2:0" bottom="row2:0"
                    skinClass="com.shinynet.shinylib.skins.CondensedStackedFormItemSkin">
            <s:TextInput width="100%"/>
        </s:FormItem>
 
        <s:FormItem label="City"
                    left="col1:3" right="col1:3" top="row3:0" bottom="row3:0"
                    skinClass="com.shinynet.shinylib.skins.CondensedStackedFormItemSkin">
            <s:TextInput width="100%"/>
        </s:FormItem>
        <s:FormItem label="State"
                    left="col2:3" right="col2:3" top="row3:0" bottom="row3:0"
                    skinClass="com.shinynet.shinylib.skins.CondensedStackedFormItemSkin">
            <s:TextInput width="100%"/>
        </s:FormItem>
        <s:FormItem label="Zip"
                    left="col3:3" right="col3:3" top="row3:0" bottom="row3:0"
                    skinClass="com.shinynet.shinylib.skins.CondensedStackedFormItemSkin">
            <s:TextInput width="100%"/>
        </s:FormItem>
    </s:Form>
 
</s:Application>

下面的内容和本文主题没什么关系,但我还是要说一下。我使用了自定义的FormItem皮肤CondensedStackedFormItemSkin,这个皮肤移除了sequenceLabelDisplay和helpContentGroup这两个外观部件,因为它们是不必要的,而且占用了太多空间。你可以从ShinyLib库中得到它们,你会发现它非常易用。

转自: http://zengrong.net/post/1572.htm
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值