• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Column
2
3沿垂直方向布局的容器。
4
5>  **说明:**
6>
7>  该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
8
9
10## 子组件
11
12可以包含子组件。
13
14
15## 接口
16
17Column(value?: {space?: string | number})
18
19从API version 9开始,该接口支持在ArkTS卡片中使用。
20
21**参数:**
22
23| 参数名 | 参数类型 | 必填 | 参数描述 |
24| -------- | -------- | -------- | -------- |
25| space | string&nbsp;\|&nbsp;number | 否 | 纵向布局元素垂直方向间距。<br/>从API version 9开始,space为负数或者justifyContent设置为FlexAlign.SpaceBetweenFlexAlign.SpaceAroundFlexAlign.SpaceEvenly时不生效。<br/>默认值:0<br/>单位:vp<br/>**说明:**<br/>可选值为大于等于0的数字,或者可以转换为数字的字符串。 |
26
27## 属性
28
29除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
30
31| 名称 | 参数类型 | 描述 |
32| -------- | -------- | -------- |
33| alignItems | [HorizontalAlign](ts-appendix-enums.md#horizontalalign) | 设置子组件在水平方向上的对齐格式。<br/>默认值:HorizontalAlign.Center<br/>从API version 9开始,该接口支持在ArkTS卡片中使用。 |
34| justifyContent<sup>8+</sup> | [FlexAlign](ts-appendix-enums.md#flexalign) | 设置子组件在垂直方向上的对齐格式。<br/>默认值:FlexAlign.Start<br/>从API version 9开始,该接口支持在ArkTS卡片中使用。 |
35
36>  **说明:**
37>
38>  Column布局时若子组件不设置[flexShrink](ts-universal-attributes-flex-layout.md#flexshrink)则默认不会压缩子组件,即所有子组件主轴大小累加可超过容器主轴。
39
40## 事件
41
42支持[通用事件](ts-universal-events-click.md)。
43
44## 示例
45
46```ts
47// xxx.ets
48@Entry
49@Component
50struct ColumnExample {
51  build() {
52    Column({ space: 5 }) {
53      // 设置子元素垂直方向间距为5
54      Text('space').width('90%')
55      Column({ space: 5 }) {
56        Column().width('100%').height(30).backgroundColor(0xAFEEEE)
57        Column().width('100%').height(30).backgroundColor(0x00FFFF)
58      }.width('90%').height(100).border({ width: 1 })
59
60      // 设置子元素水平方向对齐方式
61      Text('alignItems(Start)').width('90%')
62      Column() {
63        Column().width('50%').height(30).backgroundColor(0xAFEEEE)
64        Column().width('50%').height(30).backgroundColor(0x00FFFF)
65      }.alignItems(HorizontalAlign.Start).width('90%').border({ width: 1 })
66
67      Text('alignItems(End)').width('90%')
68      Column() {
69        Column().width('50%').height(30).backgroundColor(0xAFEEEE)
70        Column().width('50%').height(30).backgroundColor(0x00FFFF)
71      }.alignItems(HorizontalAlign.End).width('90%').border({ width: 1 })
72
73      Text('alignItems(Center)').width('90%')
74      Column() {
75        Column().width('50%').height(30).backgroundColor(0xAFEEEE)
76        Column().width('50%').height(30).backgroundColor(0x00FFFF)
77      }.alignItems(HorizontalAlign.Center).width('90%').border({ width: 1 })
78
79      // 设置子元素垂直方向的对齐方式
80      Text('justifyContent(Center)').width('90%')
81      Column() {
82        Column().width('90%').height(30).backgroundColor(0xAFEEEE)
83        Column().width('90%').height(30).backgroundColor(0x00FFFF)
84      }.height(100).border({ width: 1 }).justifyContent(FlexAlign.Center)
85
86      Text('justifyContent(End)').width('90%')
87      Column() {
88        Column().width('90%').height(30).backgroundColor(0xAFEEEE)
89        Column().width('90%').height(30).backgroundColor(0x00FFFF)
90      }.height(100).border({ width: 1 }).justifyContent(FlexAlign.End)
91    }.width('100%').padding({ top: 5 })
92  }
93}
94```
95
96![column](figures/column.png)
97