1# GridContainer 2 3The **GridContainer** component lays out components vertically. It is used only in the grid layout. 4 5> **NOTE** 6> 7> This component is deprecated since API version 9. You are advised to use [GridCol](ts-container-gridcol.md) and [GridRow](ts-container-gridrow.md) instead. 8> 9> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. 10 11 12## Child Components 13 14Supported 15 16 17## APIs 18 19GridContainer(value?: GridContainerOptions) 20 21**System capability**: SystemCapability.ArkUI.ArkUI.Full 22 23**Parameters** 24 25| Name| Type| Mandatory| Description| 26| -------- | -------- | -------- | -------- | 27| value | GridContainerOptions | No| Options of the **GridContainer** component.| 28 29## GridContainerOptions 30 31**System capability**: SystemCapability.ArkUI.ArkUI.Full 32 33| Name| Type| Mandatory| Description| 34| -------- | -------- | -------- | -------- | 35| columns | number \| 'auto' | No| Total number of columns in the current layout.<br>Default value: **'auto'**| 36| sizeType | SizeType | No| Device size type.<br>Default value: **SizeType.Auto**| 37| gutter | number \| string | No| Gutter of the grid layout. This parameter cannot be set to a percentage.| 38| margin | number \| string | No| Margin of the grid layout. This parameter cannot be set to a percentage.| 39 40## SizeType 41 42**System capability**: SystemCapability.ArkUI.ArkUI.Full 43 44| Name| Description| 45| -------- | -------- | 46| XS | Device of the minimum size.| 47| SM | Small-sized device.| 48| MD | Medium-sized device.| 49| LG | Large-sized device.| 50| Auto | Auto. The size type is selected based on the device type.| 51 52 53## Attributes 54 55The universal attributes and attributes of the [Column](ts-container-column.md#attributes) component are supported. 56 57 58## Events 59 60The universal events are supported. 61 62## Example 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