1
+ package cc.unitmesh.harmonyos.actions
2
+
3
+ enum class LayoutType (val description : String , val example : String ) {
4
+ Flex (
5
+ " 弹性布局(Flex)提供更加有效的方式对容器中的子元素进行排列、对齐和分配剩余空间。" ,
6
+ " Column({ space: 5 }) {\n " +
7
+ " Flex({ direction: FlexDirection.Row, wrap: FlexWrap.NoWrap, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {\n " +
8
+ " Text('1').width('30%').height(50).backgroundColor(0xF5DEB3)\n " +
9
+ " Text('2').width('30%').height(50).backgroundColor(0xD2B48C)\n " +
10
+ " Text('3').width('30%').height(50).backgroundColor(0xF5DEB3)\n " +
11
+ " }\n " +
12
+ " .height(70)\n " +
13
+ " .width('90%')\n " +
14
+ " .backgroundColor(0xAFEEEE)\n " +
15
+ " }.width('100%').margin({ top: 5 })"
16
+ ),
17
+ LinearLayout (
18
+ " Row/Column即线性布局(LinearLayout)是开发中最常用的布局,通过线性容器Row和Column构建。" ,
19
+ " Column({ space: 20 }) {\n " +
20
+ " Text('space: 20').fontSize(15).fontColor(Color.Gray).width('90%')\n " +
21
+ " Row().width('90%').height(50).backgroundColor(0xF5DEB3)\n " +
22
+ " Row().width('90%').height(50).backgroundColor(0xD2B48C)\n " +
23
+ " Row().width('90%').height(50).backgroundColor(0xF5DEB3)\n " +
24
+ " }.width('100%')"
25
+ ),
26
+ RelativeContainer (
27
+ " RelativeContainer为采用相对布局的容器,支持容器内部的子元素设置相对位置关系。" ,
28
+ " RelativeContainer() {\n " +
29
+ " Row()\n " +
30
+ " // 添加其他属性\n " +
31
+ " .alignRules({\n " +
32
+ " top: { anchor: '__container__', align: VerticalAlign.Top },\n " +
33
+ " left: { anchor: '__container__', align: HorizontalAlign.Start }\n " +
34
+ " })\n " +
35
+ " .id(\" row1\" )\n " +
36
+ " \n " +
37
+ " Row()\n " +
38
+ " ...\n " +
39
+ " .alignRules({\n " +
40
+ " top: { anchor: '__container__', align: VerticalAlign.Top },\n " +
41
+ " right: { anchor: '__container__', align: HorizontalAlign.End }\n " +
42
+ " })\n " +
43
+ " .id(\" row2\" )\n " +
44
+ " }\n " +
45
+ " ..."
46
+ ),
47
+
48
+ GridLayout (
49
+ " 栅格布局(GridRow/GridCol)是一种通用的辅助定位工具,对移动设备的界面设计有较好的借鉴作用。" ,
50
+ " GridRow() {\n " +
51
+ " ForEach(this.bgColors, (item, index) => {\n " +
52
+ " GridCol() {\n " +
53
+ " Row() {\n " +
54
+ " Text(`\$ {index + 1}`)\n " +
55
+ " }.width('100%').height('50')\n " +
56
+ " }.backgroundColor(item)\n " +
57
+ " })\n " +
58
+ " } "
59
+ ),
60
+ List (
61
+ " 列表是一种复杂的容器,当列表项达到一定数量,内容超过屏幕大小时,可以自动提供滚动功能。" ,
62
+ " List() {\n " +
63
+ " ListItem() {\n " +
64
+ " Text('北京').fontSize(24)\n " +
65
+ " }\n " +
66
+ " ListItem() {\n " +
67
+ " Text('杭州').fontSize(24)\n " +
68
+ " }\n " +
69
+ " ListItem() {\n " +
70
+ " Text('上海').fontSize(24)\n " +
71
+ " }\n " +
72
+ " }\n " +
73
+ " .backgroundColor('#FFF1F3F5')\n " +
74
+ " .alignListItem(ListItemAlign.Center)"
75
+ ),
76
+ StackLayout (
77
+ " 层叠布局(StackLayout)用于在屏幕上预留一块区域来显示组件中的元素,提供元素可以重叠的布局。" ,
78
+ " Stack({ alignContent: Alignment.Bottom }) {\n " +
79
+ " Flex({ wrap: FlexWrap.Wrap }) {\n " +
80
+ " ForEach(this.arr, (item) => {\n " +
81
+ " Text(item)\n " +
82
+ " .width(100)\n " +
83
+ " .height(100)\n " +
84
+ " .fontSize(16)\n " +
85
+ " .margin(10)\n " +
86
+ " .textAlign(TextAlign.Center)\n " +
87
+ " .borderRadius(10)\n " +
88
+ " .backgroundColor(0xFFFFFF)\n " +
89
+ " }, item => item)\n " +
90
+ " }.width('100%').height('100%')\n " +
91
+ " Flex({ justifyContent: FlexAlign.SpaceAround, alignItems: ItemAlign.Center }) {\n " +
92
+ " Text('联系人').fontSize(16)\n " +
93
+ " Text('设置').fontSize(16)\n " +
94
+ " Text('短信').fontSize(16)\n " +
95
+ " }\n " +
96
+ " .width('50%')\n " +
97
+ " .height(50)\n " +
98
+ " .backgroundColor('#16302e2e')\n " +
99
+ " .margin({ bottom: 15 })\n " +
100
+ " .borderRadius(15)\n " +
101
+ " }.width('100%').height('100%').backgroundColor('#CFD0CF')\n " +
102
+ " }"
103
+ )
104
+ }
0 commit comments