1e41f4b71Sopenharmony_ci# Responsive Grid Layout (GridRow/GridCol) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## Overview 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ciAs an auxiliary positioning tool, the responsive grid layout is handy in UI design on mobile devices. It exhibits the following advantages: 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci1. Provides rules for layout design and resolves issues of dynamic layout across devices with different sizes. By dividing a page into equal-width columns and rows, you can easily locate and typeset page elements. 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci2. Provides a unified positioning method for the system to ensure layout consistency across layouts on different devices. This can reduce the complexity of design and development and improve work efficiency. 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci3. Provides a flexible spacing adjustment method for applications to accommodate special layout requirements. You can adjust the spacing between columns and between rows to control the typesetting of the entire page. 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci4. Completes the wrapping and adaptation automatically when overflow occurs. When the number of page elements exceeds the capacity of a row or column, they automatically wrap to a new row or column and adapt the typesetting to different devices. 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ciThe [\<GridRow>](../reference/apis-arkui/arkui-ts/ts-container-gridrow.md) component is a responsive grid container and must have [\<GridCol>](../reference/arkui-ts/ts-container-gridcol.md) as its child component. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci## GridRow 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci### Grid Breakpoints 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ciThe grid system defines breakpoints, which are screen width types in effect, based on the horizontal width ([screen density pixels](../reference/apis-arkui/arkui-ts/ts-pixel-units.md), in vp) of the screens. You can use the breakpoints to meet specific layout requirements. You can use the breakpoints to meet specific layout requirements. 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ciBy default, the grid system provides four breakpoints: xs, sm, md, and lg. 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci| Breakpoint| Value Range (vp) | Device Description | 29e41f4b71Sopenharmony_ci| ---- | --------------- | --------- | 30e41f4b71Sopenharmony_ci| xs | [0, 320) | Minimum-width device.| 31e41f4b71Sopenharmony_ci| sm | [320, 520) | Small-width device. | 32e41f4b71Sopenharmony_ci| md | [520, 840) | Medium-width device.| 33e41f4b71Sopenharmony_ci| lg | [840, +∞) | Large-width device. | 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ciIn the **\<GridRow>** component, you can use **breakpoints** to customize the value range of breakpoints. A maximum of six breakpoints are supported. In addition to the four default breakpoints, you can also enable the xl and xxl breakpoints for your application window layout. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci| Breakpoint| Device Description | 38e41f4b71Sopenharmony_ci| ---- | --------- | 39e41f4b71Sopenharmony_ci| xs | Minimum-width device.| 40e41f4b71Sopenharmony_ci| sm | Small-width device. | 41e41f4b71Sopenharmony_ci| md | Medium-width device.| 42e41f4b71Sopenharmony_ci| lg | Large-width device. | 43e41f4b71Sopenharmony_ci| xl | Extra-large-width device.| 44e41f4b71Sopenharmony_ci| xxl | Extra-extra-large-width device.| 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci- Set **breakpoints** with a monotonically increasing array based on the use case. As **breakpoints** supports a maximum of six breakpoints, the maximum length of the monotonically increasing array is 5. 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci ```ts 50e41f4b71Sopenharmony_ci breakpoints: {value: ['100vp', '200vp']} 51e41f4b71Sopenharmony_ci ``` 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci Enables three breakpoints: xs, sm, and md. If the value is less than 100 vp, the breakpoint is xs. If the value is 100–200 vp, the breakpoint is sm. If the value is greater than 200 vp, the breakpoint is md. 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci ```ts 57e41f4b71Sopenharmony_ci breakpoints: {value: ['320vp', '520vp', '840vp', '1080vp']} 58e41f4b71Sopenharmony_ci ``` 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci Enables five breakpoints: xs, sm, md, lg, and xl. If the value is less than 320 vp, the breakpoint is xs. If the value is 320–520 vp, the breakpoint is sm. If the value is 520–840 vp, the breakpoint is md. If the value is 840–1080 vp, the breakpoint is lg. If the value is greater than 1080 vp, the breakpoint is xl. 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci- The grid system implements breakpoints by listening for the changes in the window or container size, and sets the breakpoint references through **reference**. Since the application may be displayed in non-full-screen mode, it is better to design the breakpoints with the application window width as the reference. 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ciIn the following example, the default number of grid columns is 12. Breakpoints are used to divide the application window width into six ranges. In different ranges, the **\<GridCol>** child component occupies a different number of columns. 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci```ts 68e41f4b71Sopenharmony_ci@State bgColors: Color[] = [Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Pink, Color.Grey, Color.Blue, Color.Brown]; 69e41f4b71Sopenharmony_ci... 70e41f4b71Sopenharmony_ciGridRow({ 71e41f4b71Sopenharmony_ci breakpoints: { 72e41f4b71Sopenharmony_ci value: ['200vp', '300vp', '400vp', '500vp', '600vp'], 73e41f4b71Sopenharmony_ci reference: BreakpointsReference.WindowSize 74e41f4b71Sopenharmony_ci } 75e41f4b71Sopenharmony_ci}) { 76e41f4b71Sopenharmony_ci ForEach(this.bgColors, (color:Color, index?:number|undefined) => { 77e41f4b71Sopenharmony_ci GridCol({ 78e41f4b71Sopenharmony_ci span: { 79e41f4b71Sopenharmony_ci xs: 2, // The <GridCol> component occupies two grid columns on the minimum-width device. 80e41f4b71Sopenharmony_ci sm: 3, // The <GridCol> component occupies three grid columns on the small-width device. 81e41f4b71Sopenharmony_ci md: 4, // The <GridCol> component occupies four grid columns on the medium-width device. 82e41f4b71Sopenharmony_ci lg: 6, // The <GridCol> component occupies six grid columns on the large-width device. 83e41f4b71Sopenharmony_ci xl: 8, // The <GridCol> component occupies eight grid columns on the extra-large-width device. 84e41f4b71Sopenharmony_ci xxl: 12 // The <GridCol> component occupies 12 grid columns on the extra-extra-large-width device. 85e41f4b71Sopenharmony_ci } 86e41f4b71Sopenharmony_ci }) { 87e41f4b71Sopenharmony_ci Row() { 88e41f4b71Sopenharmony_ci Text(`${index}`) 89e41f4b71Sopenharmony_ci }.width("100%").height('50vp') 90e41f4b71Sopenharmony_ci }.backgroundColor(color) 91e41f4b71Sopenharmony_ci }) 92e41f4b71Sopenharmony_ci} 93e41f4b71Sopenharmony_ci``` 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci### Columns 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ciIn the **\<GridRow>**, **columns** is used to set the total number of columns in the responsive grid layout. 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci- The default value of **columns** is 12. If **columns** is not set, the responsive grid layout is divided into 12 columns at any breakpoint. 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci ```ts 106e41f4b71Sopenharmony_ci @State bgColors: Color[] = [Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Pink, Color.Grey, Color.Blue, Color.Brown,Color.Red, Color.Orange, Color.Yellow, Color.Green]; 107e41f4b71Sopenharmony_ci ... 108e41f4b71Sopenharmony_ci GridRow() { 109e41f4b71Sopenharmony_ci ForEach(this.bgColors, (item:Color, index?:number|undefined) => { 110e41f4b71Sopenharmony_ci GridCol() { 111e41f4b71Sopenharmony_ci Row() { 112e41f4b71Sopenharmony_ci Text(`${index}`) 113e41f4b71Sopenharmony_ci }.width('100%').height('50') 114e41f4b71Sopenharmony_ci }.backgroundColor(item) 115e41f4b71Sopenharmony_ci }) 116e41f4b71Sopenharmony_ci } 117e41f4b71Sopenharmony_ci ``` 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci  120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci- When **columns** is set to a number, the responsive grid layout is divided into the specified number of columns regardless of the screen size. The following example sets the number of grid layout columns to 4 and 8 in sequence, where a child component occupies one column by default. 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci ```ts 124e41f4b71Sopenharmony_ci class CurrTmp{ 125e41f4b71Sopenharmony_ci currentBp: string = 'unknown'; 126e41f4b71Sopenharmony_ci set(val:string){ 127e41f4b71Sopenharmony_ci this.currentBp = val 128e41f4b71Sopenharmony_ci } 129e41f4b71Sopenharmony_ci } 130e41f4b71Sopenharmony_ci let BorderWH:Record<string,Color|number> = { 'color': Color.Blue, 'width': 2 } 131e41f4b71Sopenharmony_ci @State bgColors: Color[] = [Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Pink, Color.Grey, Color.Blue, Color.Brown]; 132e41f4b71Sopenharmony_ci @State currentBp: string = 'unknown'; 133e41f4b71Sopenharmony_ci ... 134e41f4b71Sopenharmony_ci Row() { 135e41f4b71Sopenharmony_ci GridRow({ columns: 4 }) { 136e41f4b71Sopenharmony_ci ForEach(this.bgColors, (item:Color, index?:number|undefined) => { 137e41f4b71Sopenharmony_ci GridCol() { 138e41f4b71Sopenharmony_ci Row() { 139e41f4b71Sopenharmony_ci Text(`${index}`) 140e41f4b71Sopenharmony_ci }.width('100%').height('50') 141e41f4b71Sopenharmony_ci }.backgroundColor(item) 142e41f4b71Sopenharmony_ci }) 143e41f4b71Sopenharmony_ci } 144e41f4b71Sopenharmony_ci .width('100%').height('100%') 145e41f4b71Sopenharmony_ci .onBreakpointChange((breakpoint:string) => { 146e41f4b71Sopenharmony_ci let CurrSet:CurrTmp = new CurrTmp() 147e41f4b71Sopenharmony_ci CurrSet.set(breakpoint) 148e41f4b71Sopenharmony_ci }) 149e41f4b71Sopenharmony_ci } 150e41f4b71Sopenharmony_ci .height(160) 151e41f4b71Sopenharmony_ci .border(BorderWH) 152e41f4b71Sopenharmony_ci .width('90%') 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci Row() { 155e41f4b71Sopenharmony_ci GridRow({ columns: 8 }) { 156e41f4b71Sopenharmony_ci ForEach(this.bgColors, (item:Color, index?:number|undefined) => { 157e41f4b71Sopenharmony_ci GridCol() { 158e41f4b71Sopenharmony_ci Row() { 159e41f4b71Sopenharmony_ci Text(`${index}`) 160e41f4b71Sopenharmony_ci }.width('100%').height('50') 161e41f4b71Sopenharmony_ci }.backgroundColor(item) 162e41f4b71Sopenharmony_ci }) 163e41f4b71Sopenharmony_ci } 164e41f4b71Sopenharmony_ci .width('100%').height('100%') 165e41f4b71Sopenharmony_ci .onBreakpointChange((breakpoint:string) => { 166e41f4b71Sopenharmony_ci let CurrSet:CurrTmp = new CurrTmp() 167e41f4b71Sopenharmony_ci CurrSet.set(breakpoint) 168e41f4b71Sopenharmony_ci }) 169e41f4b71Sopenharmony_ci } 170e41f4b71Sopenharmony_ci .height(160) 171e41f4b71Sopenharmony_ci .border(BorderWH) 172e41f4b71Sopenharmony_ci .width('90%') 173e41f4b71Sopenharmony_ci ``` 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci  176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci- When **columns** is set to a value of the **GridRowColumnOption** type, you can assign values specific to the screen size (xs, sm, md, lg, xl, xxl). 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci ```ts 180e41f4b71Sopenharmony_ci @State bgColors: Color[] = [Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Pink, Color.Grey, Color.Blue, Color.Brown] 181e41f4b71Sopenharmony_ci GridRow({ columns: { sm: 4, md: 8 }, breakpoints: { value: ['200vp', '300vp', '400vp', '500vp', '600vp'] } }) { 182e41f4b71Sopenharmony_ci ForEach(this.bgColors, (item:Color, index?:number|undefined) => { 183e41f4b71Sopenharmony_ci GridCol() { 184e41f4b71Sopenharmony_ci Row() { 185e41f4b71Sopenharmony_ci Text(`${index}`) 186e41f4b71Sopenharmony_ci }.width('100%').height('50') 187e41f4b71Sopenharmony_ci }.backgroundColor(item) 188e41f4b71Sopenharmony_ci }) 189e41f4b71Sopenharmony_ci } 190e41f4b71Sopenharmony_ci ``` 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci  193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ciIf **columns** is only set for the sm and md screen size types, screen sizes smaller than sm use the default value **12**, and screen sizes larger than md (lg, xl, and xxl) use the value of **columns** of the md type. 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci### Alignment 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ciIn the responsive grid layout, you can set the **direction** attribute of **\<GridRow>** to define the direction in which child components are arranged. The options are **GridRowDirection.Row** (from left to right) or **GridRowDirection.RowReverse** (from right to left). An appropriate **direction** value can make the page layout more flexible and meet the design requirements. 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci- When child components are arranged from left to right (default): 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ci ```ts 205e41f4b71Sopenharmony_ci GridRow({ direction: GridRowDirection.Row }){} 206e41f4b71Sopenharmony_ci ``` 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci  209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci- When child components are arranged from right to left (default): 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci ```ts 214e41f4b71Sopenharmony_ci GridRow({ direction: GridRowDirection.RowReverse }){} 215e41f4b71Sopenharmony_ci ``` 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci  218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ci### Gutters 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ciIn the **\<GridRow>** component, **gutter** is used to set the spacing between adjacent child components in the horizontal and vertical directions. 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ci- When **gutter** is set to a number, the number applies to both the horizontal and vertical directions. In the following example, the horizontal and vertical spacing between adjacent child components is set to **10**. 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci ```ts 228e41f4b71Sopenharmony_ci GridRow({ gutter: 10 }){} 229e41f4b71Sopenharmony_ci ``` 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci  232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci- When **gutter** is set to a value of the **GutterOption** type, the **x** attribute of the value indicates the horizontal gutter, and the **y** attribute indicates the vertical gutter. 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci ```ts 237e41f4b71Sopenharmony_ci GridRow({ gutter: { x: 20, y: 50 } }){} 238e41f4b71Sopenharmony_ci ``` 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci  241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci## GridCol 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_ciThe **\<GridCol>** component is a child component of the **\<GridRow>** component. You can set the **span**, **offset**, and **order** attributes of this component by passing parameters or using setters. 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ci- Setting **span** 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci ```ts 251e41f4b71Sopenharmony_ci let Gspan:Record<string,number> = { 'xs': 1, 'sm': 2, 'md': 3, 'lg': 4 } 252e41f4b71Sopenharmony_ci GridCol({ span: 2 }){} 253e41f4b71Sopenharmony_ci GridCol({ span: { xs: 1, sm: 2, md: 3, lg: 4 } }){} 254e41f4b71Sopenharmony_ci GridCol(){}.span(2) 255e41f4b71Sopenharmony_ci GridCol(){}.span(Gspan) 256e41f4b71Sopenharmony_ci ``` 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci- Setting **offset** 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci ```ts 262e41f4b71Sopenharmony_ci let Goffset:Record<string,number> = { 'xs': 1, 'sm': 2, 'md': 3, 'lg': 4 } 263e41f4b71Sopenharmony_ci GridCol({ offset: 2 }){} 264e41f4b71Sopenharmony_ci GridCol({ offset: { xs: 2, sm: 2, md: 2, lg: 2 } }){} 265e41f4b71Sopenharmony_ci GridCol(){}.offset(Goffset) 266e41f4b71Sopenharmony_ci ``` 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ci- Setting **order** 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci ```ts 272e41f4b71Sopenharmony_ci let Gorder:Record<string,number> = { 'xs': 1, 'sm': 2, 'md': 3, 'lg': 4 } 273e41f4b71Sopenharmony_ci GridCol({ order: 2 }){} 274e41f4b71Sopenharmony_ci GridCol({ order: { xs: 1, sm: 2, md: 3, lg: 4 } }){} 275e41f4b71Sopenharmony_ci GridCol(){}.order(2) 276e41f4b71Sopenharmony_ci GridCol(){}.order(Gorder) 277e41f4b71Sopenharmony_ci ``` 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci### span 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ciSets the number of columns occupied by a child component in the grid layout, which determines the child component width. The default value is **1**. 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci- When the value type is number, the number of columns occupied by the child component is the same across screen sizes. 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ci 287e41f4b71Sopenharmony_ci ```ts 288e41f4b71Sopenharmony_ci @State bgColors: Color[] = [Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Pink, Color.Grey, Color.Blue, Color.Brown]; 289e41f4b71Sopenharmony_ci ... 290e41f4b71Sopenharmony_ci GridRow({ columns: 8 }) { 291e41f4b71Sopenharmony_ci ForEach(this.bgColors, (color:Color, index?:number|undefined) => { 292e41f4b71Sopenharmony_ci GridCol({ span: 2 }) { 293e41f4b71Sopenharmony_ci Row() { 294e41f4b71Sopenharmony_ci Text(`${index}`) 295e41f4b71Sopenharmony_ci }.width('100%').height('50vp') 296e41f4b71Sopenharmony_ci } 297e41f4b71Sopenharmony_ci .backgroundColor(color) 298e41f4b71Sopenharmony_ci }) 299e41f4b71Sopenharmony_ci } 300e41f4b71Sopenharmony_ci ``` 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ci  303e41f4b71Sopenharmony_ci 304e41f4b71Sopenharmony_ci- When the value type is **GridColColumnOption**, you can assign values specific to the screen size (xs, sm, md, lg, xl, xxl). 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ci ```ts 308e41f4b71Sopenharmony_ci @State bgColors: Color[] = [Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Pink, Color.Grey, Color.Blue, Color.Brown]; 309e41f4b71Sopenharmony_ci ... 310e41f4b71Sopenharmony_ci GridRow({ columns: 8 }) { 311e41f4b71Sopenharmony_ci ForEach(this.bgColors, (color:Color, index?:number|undefined) => { 312e41f4b71Sopenharmony_ci GridCol({ span: { xs: 1, sm: 2, md: 3, lg: 4 } }) { 313e41f4b71Sopenharmony_ci Row() { 314e41f4b71Sopenharmony_ci Text(`${index}`) 315e41f4b71Sopenharmony_ci }.width('100%').height('50vp') 316e41f4b71Sopenharmony_ci } 317e41f4b71Sopenharmony_ci .backgroundColor(color) 318e41f4b71Sopenharmony_ci }) 319e41f4b71Sopenharmony_ci } 320e41f4b71Sopenharmony_ci ``` 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_ci  323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ci### offset 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ciSets the column offset of a child component relative to the previous child component. The default value is **0**. 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ci- When the value type is number, the column offset of the child component is the same across screen sizes. 330e41f4b71Sopenharmony_ci 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci ```ts 333e41f4b71Sopenharmony_ci @State bgColors: Color[] = [Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Pink, Color.Grey, Color.Blue, Color.Brown]; 334e41f4b71Sopenharmony_ci ... 335e41f4b71Sopenharmony_ci GridRow() { 336e41f4b71Sopenharmony_ci ForEach(this.bgColors, (color:Color, index?:number|undefined) => { 337e41f4b71Sopenharmony_ci GridCol({ offset: 2 }) { 338e41f4b71Sopenharmony_ci Row() { 339e41f4b71Sopenharmony_ci Text('' + index) 340e41f4b71Sopenharmony_ci }.width('100%').height('50vp') 341e41f4b71Sopenharmony_ci } 342e41f4b71Sopenharmony_ci .backgroundColor(color) 343e41f4b71Sopenharmony_ci }) 344e41f4b71Sopenharmony_ci } 345e41f4b71Sopenharmony_ci ``` 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci  348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci By default, a grid is divided into 12 columns and each child component occupies one column with an offset of two columns. Each row holds four child components, with three columns per child component plus the gutter. 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ci- When the value type is **GridColColumnOption**, you can assign values specific to the screen size (xs, sm, md, lg, xl, xxl). 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci ```ts 355e41f4b71Sopenharmony_ci @State bgColors: Color[] = [Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Pink, Color.Grey, Color.Blue, Color.Brown]; 356e41f4b71Sopenharmony_ci ... 357e41f4b71Sopenharmony_ci 358e41f4b71Sopenharmony_ci GridRow() { 359e41f4b71Sopenharmony_ci ForEach(this.bgColors, (color:Color, index?:number|undefined) => { 360e41f4b71Sopenharmony_ci GridCol({ offset: { xs: 1, sm: 2, md: 3, lg: 4 } }) { 361e41f4b71Sopenharmony_ci Row() { 362e41f4b71Sopenharmony_ci Text('' + index) 363e41f4b71Sopenharmony_ci }.width('100%').height('50vp') 364e41f4b71Sopenharmony_ci } 365e41f4b71Sopenharmony_ci .backgroundColor(color) 366e41f4b71Sopenharmony_ci }) 367e41f4b71Sopenharmony_ci } 368e41f4b71Sopenharmony_ci ``` 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_ci  371e41f4b71Sopenharmony_ci 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci### order 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_ciSets the sequence number of a child component in the grid layout. If a child component shares an **order** value with another child component or does not have **order** set, it is displayed based on its code sequence number. A child component with a smaller **order** value is placed before the one with a larger **order** value. 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ciIf **order** is not set for all child components, those that have **order** set are displayed after those that do not have **order** set and are sorted in ascending order based on the value. 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci- When the value type is number, child components are sorted in the same order across screen sizes. 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ci 382e41f4b71Sopenharmony_ci ```ts 383e41f4b71Sopenharmony_ci GridRow() { 384e41f4b71Sopenharmony_ci GridCol({ order: 4 }) { 385e41f4b71Sopenharmony_ci Row() { 386e41f4b71Sopenharmony_ci Text('1') 387e41f4b71Sopenharmony_ci }.width('100%').height('50vp') 388e41f4b71Sopenharmony_ci }.backgroundColor(Color.Red) 389e41f4b71Sopenharmony_ci GridCol({ order: 3 }) { 390e41f4b71Sopenharmony_ci Row() { 391e41f4b71Sopenharmony_ci Text('2') 392e41f4b71Sopenharmony_ci }.width('100%').height('50vp') 393e41f4b71Sopenharmony_ci }.backgroundColor(Color.Orange) 394e41f4b71Sopenharmony_ci GridCol({ order: 2 }) { 395e41f4b71Sopenharmony_ci Row() { 396e41f4b71Sopenharmony_ci Text('3') 397e41f4b71Sopenharmony_ci }.width('100%').height('50vp') 398e41f4b71Sopenharmony_ci }.backgroundColor(Color.Yellow) 399e41f4b71Sopenharmony_ci GridCol({ order: 1 }) { 400e41f4b71Sopenharmony_ci Row() { 401e41f4b71Sopenharmony_ci Text('4') 402e41f4b71Sopenharmony_ci }.width('100%').height('50vp') 403e41f4b71Sopenharmony_ci }.backgroundColor(Color.Green) 404e41f4b71Sopenharmony_ci } 405e41f4b71Sopenharmony_ci ``` 406e41f4b71Sopenharmony_ci 407e41f4b71Sopenharmony_ci  408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_ci- When the value type is **GridColColumnOption**, you can assign values specific to the screen size (xs, sm, md, lg, xl, xxl). You can set 1234 for xs, 2341 for sm, 3412 for md, and 2431 for lg. 410e41f4b71Sopenharmony_ci 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci ```ts 413e41f4b71Sopenharmony_ci GridRow() { 414e41f4b71Sopenharmony_ci GridCol({ order: { xs:1, sm:5, md:3, lg:7}}) { 415e41f4b71Sopenharmony_ci Row() { 416e41f4b71Sopenharmony_ci Text('1') 417e41f4b71Sopenharmony_ci }.width('100%').height('50vp') 418e41f4b71Sopenharmony_ci }.backgroundColor(Color.Red) 419e41f4b71Sopenharmony_ci GridCol({ order: { xs:2, sm:2, md:6, lg:1} }) { 420e41f4b71Sopenharmony_ci Row() { 421e41f4b71Sopenharmony_ci Text('2') 422e41f4b71Sopenharmony_ci }.width('100%').height('50vp') 423e41f4b71Sopenharmony_ci }.backgroundColor(Color.Orange) 424e41f4b71Sopenharmony_ci GridCol({ order: { xs:3, sm:3, md:1, lg:6} }) { 425e41f4b71Sopenharmony_ci Row() { 426e41f4b71Sopenharmony_ci Text('3') 427e41f4b71Sopenharmony_ci }.width('100%').height('50vp') 428e41f4b71Sopenharmony_ci }.backgroundColor(Color.Yellow) 429e41f4b71Sopenharmony_ci GridCol({ order: { xs:4, sm:4, md:2, lg:5} }) { 430e41f4b71Sopenharmony_ci Row() { 431e41f4b71Sopenharmony_ci Text('4') 432e41f4b71Sopenharmony_ci }.width('100%').height('50vp') 433e41f4b71Sopenharmony_ci }.backgroundColor(Color.Green) 434e41f4b71Sopenharmony_ci } 435e41f4b71Sopenharmony_ci ``` 436e41f4b71Sopenharmony_ci 437e41f4b71Sopenharmony_ci  438e41f4b71Sopenharmony_ci 439e41f4b71Sopenharmony_ci 440e41f4b71Sopenharmony_ci## Nesting of Responsive Grid Components 441e41f4b71Sopenharmony_ci 442e41f4b71Sopenharmony_ciResponsive grid components can be contained in other responsive grid components. 443e41f4b71Sopenharmony_ci 444e41f4b71Sopenharmony_ciIn the following example, the responsive grid divides the entire space into 12 parts. At the first layer, **\<GridCol>** is nested in **\<GridRow>**, and the space is divided into the large area in the center and the footer area. At the second layer, **\<GridCol>** is nested in **\<GridRow>**, and the space is divided into the left and right areas. The child components take up the space allocated by the parent component at the upper layer. In this example, the pink area is made up of 12 columns of the screen space, and the green and blue areas take up the 12 columns of the parent component proportionally. 445e41f4b71Sopenharmony_ci 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_ci```ts 449e41f4b71Sopenharmony_ci@Entry 450e41f4b71Sopenharmony_ci@Component 451e41f4b71Sopenharmony_cistruct GridRowExample { 452e41f4b71Sopenharmony_ci build() { 453e41f4b71Sopenharmony_ci GridRow() { 454e41f4b71Sopenharmony_ci GridCol({ span: { sm: 12 } }) { 455e41f4b71Sopenharmony_ci GridRow() { 456e41f4b71Sopenharmony_ci GridCol({ span: { sm: 2 } }) { 457e41f4b71Sopenharmony_ci Row() { 458e41f4b71Sopenharmony_ci Text('left').fontSize(24) 459e41f4b71Sopenharmony_ci } 460e41f4b71Sopenharmony_ci .justifyContent(FlexAlign.Center) 461e41f4b71Sopenharmony_ci .height('90%') 462e41f4b71Sopenharmony_ci }.backgroundColor('#ff41dbaa') 463e41f4b71Sopenharmony_ci 464e41f4b71Sopenharmony_ci GridCol({ span: { sm: 10 } }) { 465e41f4b71Sopenharmony_ci Row() { 466e41f4b71Sopenharmony_ci Text('right').fontSize(24) 467e41f4b71Sopenharmony_ci } 468e41f4b71Sopenharmony_ci .justifyContent(FlexAlign.Center) 469e41f4b71Sopenharmony_ci .height('90%') 470e41f4b71Sopenharmony_ci }.backgroundColor('#ff4168db') 471e41f4b71Sopenharmony_ci } 472e41f4b71Sopenharmony_ci .backgroundColor('#19000000') 473e41f4b71Sopenharmony_ci .height('100%') 474e41f4b71Sopenharmony_ci } 475e41f4b71Sopenharmony_ci 476e41f4b71Sopenharmony_ci GridCol({ span: { sm: 12 } }) { 477e41f4b71Sopenharmony_ci Row() { 478e41f4b71Sopenharmony_ci Text('footer').width('100%').textAlign(TextAlign.Center) 479e41f4b71Sopenharmony_ci }.width('100%').height('10%').backgroundColor(Color.Pink) 480e41f4b71Sopenharmony_ci } 481e41f4b71Sopenharmony_ci }.width('100%').height(300) 482e41f4b71Sopenharmony_ci } 483e41f4b71Sopenharmony_ci} 484e41f4b71Sopenharmony_ci``` 485e41f4b71Sopenharmony_ci 486e41f4b71Sopenharmony_ci 487e41f4b71Sopenharmony_ci 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci 490e41f4b71Sopenharmony_ciTo sum up, the responsive grid components are powerful tools with a wide range of customization capabilities. With the required attributes set at different breakpoints, such as **Columns**, **Margin**, **Gutter**, and **span**, the layout is created automatically. You do not need to pay attention to the specific device type and device state (such as landscape and portrait). 491