ts-container-column.md 2.7 KB
Newer Older
Z
zengyawen 已提交
1 2
# Column

Z
zengyawen 已提交
3 4
沿垂直方向布局的容器。

G
gmy 已提交
5 6 7
>  **说明:**
>
>  该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
Z
zengyawen 已提交
8

Z
zengyawen 已提交
9 10

## 子组件
Z
zengyawen 已提交
11 12 13

可以包含子组件。

Z
zengyawen 已提交
14 15 16

## 接口

T
tianyu 已提交
17
Column(value?: {space?: string | number})
Z
zengyawen 已提交
18

G
gmy 已提交
19
**参数:**
Z
zengyawen 已提交
20

G
gmy 已提交
21 22
| 参数名 | 参数类型 | 必填 | 参数描述 |
| -------- | -------- | -------- | -------- |
23
| space | string&nbsp;\|&nbsp;number | 否 | 纵向布局元素间距。<br/>默认值:0 |
Z
zengyawen 已提交
24 25 26

## 属性

G
gmy 已提交
27
除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
Z
zengyawen 已提交
28

G
gmy 已提交
29 30 31 32
| 名称 | 参数类型 | 描述 |
| -------- | -------- | -------- |
| alignItems | [HorizontalAlign](ts-appendix-enums.md#horizontalalign) | 设置子组件在水平方向上的对齐格式。<br/>默认值:HorizontalAlign.Center |
| justifyContent<sup>8+</sup> | [FlexAlign](ts-container-flex.md) | 设置子组件在垂直方向上的对齐格式。<br/>默认值:FlexAlign.Start |
Z
zengyawen 已提交
33 34

## 示例
Z
zengyawen 已提交
35

H
geshi  
HelloCrease 已提交
36 37
```ts
// xxx.ets
Z
zengyawen 已提交
38 39 40 41
@Entry
@Component
struct ColumnExample {
  build() {
42 43
    Column() {
        Text('space').fontSize(9).fontColor(0xCCCCCC).width('90%')
Z
zhongyuyan 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
        Column({ space: 5 }) {
          Column().width('100%').height(30).backgroundColor(0xAFEEEE)
          Column().width('100%').height(30).backgroundColor(0x00FFFF)
        }.width('90%').height(100).border({ width: 1 })

        Text('alignItems(Start)').fontSize(9).fontColor(0xCCCCCC).width('90%')
        Column() {
          Column().width('50%').height(30).backgroundColor(0xAFEEEE)
          Column().width('50%').height(30).backgroundColor(0x00FFFF)
        }.alignItems(HorizontalAlign.Start).width('90%').border({ width: 1 })

        Text('alignItems(End)').fontSize(9).fontColor(0xCCCCCC).width('90%')
        Column() {
          Column().width('50%').height(30).backgroundColor(0xAFEEEE)
          Column().width('50%').height(30).backgroundColor(0x00FFFF)
        }.alignItems(HorizontalAlign.End).width('90%').border({ width: 1 })

        Text('justifyContent(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%')
        Column() {
          Column().width('30%').height(30).backgroundColor(0xAFEEEE)
          Column().width('30%').height(30).backgroundColor(0x00FFFF)
        }.height('15%').border({ width: 1 }).justifyContent(FlexAlign.Center)

        Text('justifyContent(End)').fontSize(9).fontColor(0xCCCCCC).width('90%')
        Column() {
          Column().width('30%').height(30).backgroundColor(0xAFEEEE)
          Column().width('30%').height(30).backgroundColor(0x00FFFF)
        }.height('15%').border({ width: 1 }).justifyContent(FlexAlign.End)
Z
zengyawen 已提交
72 73 74 75 76
    }.width('100%').padding({ top: 5 })
  }
}
```

Z
zengyawen 已提交
77
![zh-cn_image_0000001219982721](figures/Column.png)