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 \| number | 否 | 纵向布局元素垂直方向间距。<br/>从API version 9开始,space为负数或者justifyContent设置为FlexAlign.SpaceBetween、FlexAlign.SpaceAround、FlexAlign.SpaceEvenly时不生效。<br/>默认值:0<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则默认不会压缩子组件,即所有子组件主轴大小累加可超过容器主轴。 39 40## 示例 41 42```ts 43// xxx.ets 44@Entry 45@Component 46struct ColumnExample { 47 build() { 48 Column({ space: 5 }) { 49 // 设置子元素垂直方向间距为5 50 Text('space').width('90%') 51 Column({ space: 5 }) { 52 Column().width('100%').height(30).backgroundColor(0xAFEEEE) 53 Column().width('100%').height(30).backgroundColor(0x00FFFF) 54 }.width('90%').height(100).border({ width: 1 }) 55 56 // 设置子元素水平方向对齐方式 57 Text('alignItems(Start)').width('90%') 58 Column() { 59 Column().width('50%').height(30).backgroundColor(0xAFEEEE) 60 Column().width('50%').height(30).backgroundColor(0x00FFFF) 61 }.alignItems(HorizontalAlign.Start).width('90%').border({ width: 1 }) 62 63 Text('alignItems(End)').width('90%') 64 Column() { 65 Column().width('50%').height(30).backgroundColor(0xAFEEEE) 66 Column().width('50%').height(30).backgroundColor(0x00FFFF) 67 }.alignItems(HorizontalAlign.End).width('90%').border({ width: 1 }) 68 69 Text('alignItems(Center)').width('90%') 70 Column() { 71 Column().width('50%').height(30).backgroundColor(0xAFEEEE) 72 Column().width('50%').height(30).backgroundColor(0x00FFFF) 73 }.alignItems(HorizontalAlign.Center).width('90%').border({ width: 1 }) 74 75 // 设置子元素垂直方向的对齐方式 76 Text('justifyContent(Center)').width('90%') 77 Column() { 78 Column().width('90%').height(30).backgroundColor(0xAFEEEE) 79 Column().width('90%').height(30).backgroundColor(0x00FFFF) 80 }.height(100).border({ width: 1 }).justifyContent(FlexAlign.Center) 81 82 Text('justifyContent(End)').width('90%') 83 Column() { 84 Column().width('90%').height(30).backgroundColor(0xAFEEEE) 85 Column().width('90%').height(30).backgroundColor(0x00FFFF) 86 }.height(100).border({ width: 1 }).justifyContent(FlexAlign.End) 87 }.width('100%').padding({ top: 5 }) 88 } 89} 90``` 91 92 93