1# GridContainer 2 3<!--deprecated_code_no_check--> 4纵向排布栅格布局容器,仅在栅格布局场景中使用。 5 6> **说明:** 7> 8> 从API Version 9 开始,该组件不再维护,推荐使用新组件[GridCol](ts-container-gridcol.md)、[GridRow](ts-container-gridrow.md)。 9> 10> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 11 12 13## 子组件 14 15可以包含子组件。 16 17 18## 接口 19 20GridContainer(value?: GridContainerOptions) 21 22**系统能力:** SystemCapability.ArkUI.ArkUI.Full 23 24**参数:** 25 26| 参数名 | 类型 | 必填 | 说明 | 27| -------- | -------- | -------- | -------- | 28| value | GridContainerOptions | 否 | GridContainer参数。 | 29 30## GridContainerOptions对象说明 31 32**系统能力:** SystemCapability.ArkUI.ArkUI.Full 33 34| 名称 | 类型 | 必填 | 说明 | 35| -------- | -------- | -------- | -------- | 36| columns | number \| 'auto' | 否 | 设置当前布局总列数。<br/>默认值:'auto' | 37| sizeType | SizeType | 否 | 选用设备宽度类型。<br/>默认值:SizeType.Auto | 38| gutter | number \| string | 否 | 栅格布局列间距,不支持百分比。 | 39| margin | number \| string | 否 | 栅格布局两侧间距,不支持百分比。 | 40 41## SizeType枚举说明 42 43**系统能力:** SystemCapability.ArkUI.ArkUI.Full 44 45| 名称 | 说明 | 46| -------- | -------- | 47| XS | 最小宽度类型设备。 | 48| SM | 小宽度类型设备。 | 49| MD | 中等宽度类型设备。 | 50| LG | 大宽度类型设备。 | 51| Auto | 根据设备类型进行选择。 | 52 53 54## 属性 55 56支持[通用属性](ts-component-general-attributes.md)和Column组件的[属性方法](ts-container-column.md#属性)。 57 58 59## 事件 60 61支持[通用事件](ts-component-general-events.md)。 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 136