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 \| 'auto' | 否 | 设置当前布局总列数。<br/>默认值:'auto' | 36| sizeType | SizeType | 否 | 选用设备宽度类型。<br/>默认值:SizeType.Auto | 37| gutter | number \| string | 否 | 栅格布局列间距,不支持百分比。 | 38| margin | number \| 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```ts 65// xxx.ets 66@Entry 67@Component 68struct GridContainerExample { 69 @State sizeType: SizeType = SizeType.XS 70 71 build() { 72 Column({ space: 5 }) { 73 GridContainer({ columns: 12, sizeType: this.sizeType, gutter: 10, margin: 20 }) { 74 Row() { 75 Text('1') 76 .useSizeType({ 77 xs: { span: 6, offset: 0 }, 78 sm: { span: 2, offset: 0 }, 79 md: { span: 2, offset: 0 }, 80 lg: { span: 2, offset: 0 } 81 }) 82 .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center) 83 Text('2') 84 .useSizeType({ 85 xs: { span: 2, offset: 6 }, 86 sm: { span: 6, offset: 2 }, 87 md: { span: 2, offset: 2 }, 88 lg: { span: 2, offset: 2 } 89 }) 90 .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center) 91 Text('3') 92 .useSizeType({ 93 xs: { span: 2, offset: 8 }, 94 sm: { span: 2, offset: 8 }, 95 md: { span: 6, offset: 4 }, 96 lg: { span: 2, offset: 4 } 97 }) 98 .height(50).backgroundColor(0x4682B4).textAlign(TextAlign.Center) 99 Text('4') 100 .useSizeType({ 101 xs: { span: 2, offset: 10 }, 102 sm: { span: 2, offset: 10 }, 103 md: { span: 2, offset: 10 }, 104 lg: { span: 6, offset: 6 } 105 }) 106 .height(50).backgroundColor(0x00BFFF).textAlign(TextAlign.Center) 107 } 108 }.width('90%') 109 110 Text('Click Simulate to change the device width').fontSize(9).width('90%').fontColor(0xCCCCCC) 111 Row() { 112 Button('XS') 113 .onClick(() => { 114 this.sizeType = SizeType.XS 115 }).backgroundColor(0x317aff) 116 Button('SM') 117 .onClick(() => { 118 this.sizeType = SizeType.SM 119 }).backgroundColor(0x317aff) 120 Button('MD') 121 .onClick(() => { 122 this.sizeType = SizeType.MD 123 }).backgroundColor(0x317aff) 124 Button('LG') 125 .onClick(() => { 126 this.sizeType = SizeType.LG 127 }).backgroundColor(0x317aff) 128 } 129 }.width('100%').margin({ top: 5 }) 130 } 131} 132``` 133 134 135