1# GridContainer
2
3纵向排布栅格布局容器,仅在栅格布局场景中使用。
4
5>  **说明:**
6>
7>  从API Version 9 开始,该组件不再维护,推荐使用新组件[GridCol](ts-container-gridcol.md)、[GridRow](ts-container-gridrow.md)。
8>
9>  该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
10
11
12## 子组件
13
14可以包含子组件。
15
16
17## 接口
18
19GridContainer(value?: GridContainerOptions)
20
21**系统能力:** SystemCapability.ArkUI.ArkUI.Full
22
23**参数:**
24
25| 参数名 | 类型 | 必填 | 说明 |
26| -------- | -------- | -------- | -------- |
27| value | GridContainerOptions | 否 | GridContainer参数 |
28
29## GridContainerOptions对象说明
30
31**系统能力:** SystemCapability.ArkUI.ArkUI.Full
32
33| 名称 | 类型 | 必填 | 说明 |
34| -------- | -------- | -------- | -------- |
35| columns | number&nbsp;\|&nbsp;'auto' | 否 | 设置当前布局总列数。<br/>默认值:'auto' |
36| sizeType | SizeType | 否 | 选用设备宽度类型。<br/>默认值:SizeType.Auto |
37| gutter | number&nbsp;\|&nbsp;string | 否 | 栅格布局列间距,不支持百分比。 |
38| margin | number&nbsp;\|&nbsp;string | 否 | 栅格布局两侧间距,不支持百分比。 |
39
40## SizeType枚举说明
41
42**系统能力:** SystemCapability.ArkUI.ArkUI.Full
43
44| 名称 | 说明 |
45| -------- | -------- |
46| XS | 最小宽度类型设备。 |
47| SM | 小宽度类型设备。 |
48| MD | 中等宽度类型设备。 |
49| LG | 大宽度类型设备。 |
50| Auto | 根据设备类型进行选择。 |
51
52
53## 属性
54
55支持通用属性和Column组件的[属性方法](ts-container-column.md#属性)。
56
57
58## 事件
59
60支持通用事件。
61
62
63## 示例
64
65```ts
66// xxx.ets
67@Entry
68@Component
69struct GridContainerExample {
70  @State sizeType: SizeType = SizeType.XS
71
72  build() {
73    Column({ space: 5 }) {
74      GridContainer({ columns: 12, sizeType: this.sizeType, gutter: 10, margin: 20 }) {
75        Row() {
76          Text('1')
77            .useSizeType({
78              xs: { span: 6, offset: 0 },
79              sm: { span: 2, offset: 0 },
80              md: { span: 2, offset: 0 },
81              lg: { span: 2, offset: 0 }
82            })
83            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
84          Text('2')
85            .useSizeType({
86              xs: { span: 2, offset: 6 },
87              sm: { span: 6, offset: 2 },
88              md: { span: 2, offset: 2 },
89              lg: { span: 2, offset: 2 }
90            })
91            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
92          Text('3')
93            .useSizeType({
94              xs: { span: 2, offset: 8 },
95              sm: { span: 2, offset: 8 },
96              md: { span: 6, offset: 4 },
97              lg: { span: 2, offset: 4 }
98            })
99            .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center)
100          Text('4')
101            .useSizeType({
102              xs: { span: 2, offset: 10 },
103              sm: { span: 2, offset: 10 },
104              md: { span: 2, offset: 10 },
105              lg: { span: 6, offset: 6 }
106            })
107            .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center)
108        }
109      }.width('90%')
110
111      Text('Click Simulate to change the device width').fontSize(9).width('90%').fontColor(0xCCCCCC)
112      Row() {
113        Button('XS')
114          .onClick(() => {
115            this.sizeType = SizeType.XS
116          }).backgroundColor(0x317aff)
117        Button('SM')
118          .onClick(() => {
119            this.sizeType = SizeType.SM
120          }).backgroundColor(0x317aff)
121        Button('MD')
122          .onClick(() => {
123            this.sizeType = SizeType.MD
124          }).backgroundColor(0x317aff)
125        Button('LG')
126          .onClick(() => {
127            this.sizeType = SizeType.LG
128          }).backgroundColor(0x317aff)
129      }
130    }.width('100%').margin({ top: 5 })
131  }
132}
133```
134
135![zh-cn_image_0000001219744187](figures/zh-cn_image_0000001219744187.gif)
136