1e41f4b71Sopenharmony_ci# GridRow 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe responsive grid layout provides rules for layout design and resolves issues of dynamic layout across devices with different sizes, thereby ensuring layout consistency across layouts on different devices. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciThe **GridRow** component is used in a grid layout, together with its child component [GridCol](ts-container-gridcol.md). 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci> **NOTE** 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> This component is supported since API version 9. Updates will be marked with a superscript to indicate their earliest API version. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci## Child Components 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ciThis component can contain the **GridCol** child component. 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## APIs 18e41f4b71Sopenharmony_ciGridRow(option?: GridRowOptions) 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci**Parameters** 25e41f4b71Sopenharmony_ci| Name |Type|Mandatory|Description| 26e41f4b71Sopenharmony_ci|-----|-----|----|----| 27e41f4b71Sopenharmony_ci| option | [GridRowOptions](#gridrowoptions) | No | Child component options of the grid layout. | 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci## GridRowOptions 30e41f4b71Sopenharmony_ci| Name |Type|Mandatory|Description| 31e41f4b71Sopenharmony_ci|-----|-----|----|----| 32e41f4b71Sopenharmony_ci|columns| number \| [GridRowColumnOption](#gridrowcolumnoption) | No |Number of columns in the grid layout.<br>Default value: **12** | 33e41f4b71Sopenharmony_ci|gutter|[Length](ts-types.md#length) \| [GutterOption](#gutteroption)| No |Gutter of the grid layout.<br>Default value: **0** | 34e41f4b71Sopenharmony_ci|breakpoints|[BreakPoints](#breakpoints)| No |Array of breakpoints for the breakpoint value and the corresponding reference based on the window or container size.<br>Default value:<br>{<br>value: ["320vp", "600vp", "840vp"],<br>reference: BreakpointsReference.WindowSize<br>} | 35e41f4b71Sopenharmony_ci|direction|[GridRowDirection](#gridrowdirection)| No |Arrangement direction of the grid layout.<br>Default value: **GridRowDirection.Row** | 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci## GutterOption 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ciProvides the gutter options for the grid layout to define the spacing between child components in different directions. 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 46e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ---------------------------------------- | 47e41f4b71Sopenharmony_ci| x | [Length](ts-types.md#length) \| [GridRowSizeOption](#gridrowsizeoption) | No | Horizontal spacing between grid child components. | 48e41f4b71Sopenharmony_ci| y | [Length](ts-types.md#length) \| [GridRowSizeOption](#gridrowsizeoption) | No | Vertical spacing between grid child components. | 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci## GridRowColumnOption 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ciDescribes the numbers of grid columns for devices with different grid sizes. 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 59e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ---------------------------------------- | 60e41f4b71Sopenharmony_ci| xs | number | No | Number of grid columns on the device where the grid size is xs. | 61e41f4b71Sopenharmony_ci| sm | number | No | Number of grid columns on the device where the grid size is sm. | 62e41f4b71Sopenharmony_ci| md | number | No | Number of grid columns on the device where the grid size is md. | 63e41f4b71Sopenharmony_ci| lg | number | No | Number of grid columns on the device where the grid size is lg. | 64e41f4b71Sopenharmony_ci| xl | number | No | Number of grid columns on the device where the grid size is xl. | 65e41f4b71Sopenharmony_ci| xxl | number | No | Number of grid columns on the device where the grid size is xxl. | 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci**NOTE** 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ciIn the **GridRow** component, you can define the value range of [breakpoints](../../../ui/arkts-layout-development-grid-layout.md#grid-breakpoints). A maximum of six breakpoints are supported, which are xs, sm, md, lg, xl, and xxl. The breakpoint names cannot be modified. Assume that the input array is [n0, n1, n2, n3, n4], then the value ranges of breakpoints are as follows. 70e41f4b71Sopenharmony_ci|Breakpoint|Value Range| 71e41f4b71Sopenharmony_ci|---|-----------| 72e41f4b71Sopenharmony_ci|xs |[0, n0) | 73e41f4b71Sopenharmony_ci|sm |[n0, n1) | 74e41f4b71Sopenharmony_ci|md |[n1, n2) | 75e41f4b71Sopenharmony_ci|lg |[n2, n3) | 76e41f4b71Sopenharmony_ci|xl |[n3, n4) | 77e41f4b71Sopenharmony_ci|xxl|[n4, INF) | 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci## GridRowSizeOption 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ciDescribes the gutter sizes for different device width types. 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 88e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ---------------------------------------- | 89e41f4b71Sopenharmony_ci| xs | [Length](ts-types.md#length) | No | Gutter size for minimum device width. | 90e41f4b71Sopenharmony_ci| sm | [Length](ts-types.md#length) | No | Gutter size for small device width. | 91e41f4b71Sopenharmony_ci| md | [Length](ts-types.md#length) | No | Gutter size for medium device width. | 92e41f4b71Sopenharmony_ci| lg | [Length](ts-types.md#length) | No | Gutter size for large device width. | 93e41f4b71Sopenharmony_ci| xl | [Length](ts-types.md#length) | No | Gutter size for extra large device width. | 94e41f4b71Sopenharmony_ci| xxl | [Length](ts-types.md#length) | No | Gutter size for extra extra large device width. | 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci## BreakPoints 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ciSets breakpoints for the responsive grid container. 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 105e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ---------------------------------------- | 106e41f4b71Sopenharmony_ci| value | Array<string> | No | Array of monotonically increasing breakpoints.<br>Default value: **["320vp", "600vp", "840vp"]** | 107e41f4b71Sopenharmony_ci| reference | [BreakpointsReference](#breakpointsreference) | No | Breakpoint switching reference.<br>Default value: **BreakpointsReference.WindowSize** | 108e41f4b71Sopenharmony_ci```ts 109e41f4b71Sopenharmony_ci // Enable the xs, sm, and md breakpoints. 110e41f4b71Sopenharmony_ci breakpoints: {value: ["100vp", "200vp"]} 111e41f4b71Sopenharmony_ci // Enable four breakpoints: xs, sm, md, and lg. The breakpoint range must be monotonically increasing. 112e41f4b71Sopenharmony_ci breakpoints: {value: ["320vp", "600vp", "840vp"]} 113e41f4b71Sopenharmony_ci // Enable five breakpoints: xs, sm, md, lg, and xl. The number of breakpoint ranges cannot exceed the number of breakpoints minus 1. 114e41f4b71Sopenharmony_ci breakpoints: {value: ["320vp", "600vp", "840vp", "1080vp"]} 115e41f4b71Sopenharmony_ci``` 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci## BreakpointsReference 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci| Name | Description | 124e41f4b71Sopenharmony_ci| -------- | -------- | 125e41f4b71Sopenharmony_ci| WindowSize | The window is used as a reference. | 126e41f4b71Sopenharmony_ci| ComponentSize | The container is used as a reference. | 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci## GridRowDirection 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci| Name | Description | 135e41f4b71Sopenharmony_ci| -------- | -------- | 136e41f4b71Sopenharmony_ci| Row | Grid elements are arranged in the row direction. | 137e41f4b71Sopenharmony_ci| RowReverse | Grid elements are arranged in the reverse row direction. | 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci**NOTE** 140e41f4b71Sopenharmony_ci* Grid elements can be arranged only in the **Row** or **RowReverse** direction, but not in the **Column** or **ColumnReverse** direction. 141e41f4b71Sopenharmony_ci* The location and size of a grid child component can be calculated only based on **span** and **offset**. If the **span** values of child components add up to a number greater than the allowed number of columns, the grid will automatically wraps lines. 142e41f4b71Sopenharmony_ci* If the **span** value of a single child component exceeds the maximum number of columns, the maximum number of columns is used. 143e41f4b71Sopenharmony_ci* If a child component takes up more than the total number of columns according to its **offset** and **span** settings, it will be placed in a new row. 144e41f4b71Sopenharmony_ci* Below is the display effect of **Item1: GridCol({span: 6}), Item2: GridCol({ span: 8, offset:11})**. 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci|1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 147e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ---- | -----|-----|---------|--------|------|------- |------- |------- | 148e41f4b71Sopenharmony_ci| $\circ$ | $\circ$ | $\circ$ | $\circ$ | $\circ$|$\circ$| - | - | - | - | - | - | 149e41f4b71Sopenharmony_ci| - | - | - | - | - | | | | | | | | 150e41f4b71Sopenharmony_ci| $\circ$ | $\circ$ | $\circ$ | $\circ$ | $\circ$|$\circ$|$\circ$|$\circ$| | | | | 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci## Attributes 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci### alignItems<sup>10+</sup> 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_cialignItems(value: ItemAlign) 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ciSets the alignment mode of the **GridCol** components along the vertical main axis of the **GridRow** component. The alignment mode of the **GridCol** component can also be set using **alignSelf([ItemAlign](ts-appendix-enums.md#itemalign))**. If both of the preceding methods are used, the setting of **alignSelf(ItemAlign)** prevails. 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 10. 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci**Parameters** 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 171e41f4b71Sopenharmony_ci| ------ | ------------------------------------------- | ---- | ------------------------------------------------------------ | 172e41f4b71Sopenharmony_ci| value | [ItemAlign](ts-appendix-enums.md#itemalign) | Yes | Alignment mode of the **GridCol** components along the vertical main axis of the **GridRow** component.<br>Default value: **ItemAlign.Start**<br>**NOTE**<br>**ItemAlign** supports the following enums: **ItemAlign.Start**, **ItemAlign.Center**, **ItemAlign.End**, and **ItemAlign.Stretch**. | 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci## Events 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci### onBreakpointChange 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_cionBreakpointChange(callback: (breakpoints: string) => void) 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ciTriggered when the breakpoint changes. 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 10. 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci**Parameters** 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 192e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ---------------------------------------- | 193e41f4b71Sopenharmony_ci|breakpoints| string |No|Breakpoint change.<br> The value can be **"xs"**, **"sm"**, **"md"**, **"lg"**, **"xl"**, or **"xxl"**.| 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci## Example 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci```ts 198e41f4b71Sopenharmony_ci// xxx.ets 199e41f4b71Sopenharmony_ci@Entry 200e41f4b71Sopenharmony_ci@Component 201e41f4b71Sopenharmony_cistruct GridRowExample { 202e41f4b71Sopenharmony_ci @State bgColors: Color[] = [Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Pink, Color.Grey, Color.Blue, Color.Brown] 203e41f4b71Sopenharmony_ci @State currentBp: string = 'unknown' 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci build() { 206e41f4b71Sopenharmony_ci Column() { 207e41f4b71Sopenharmony_ci GridRow({ 208e41f4b71Sopenharmony_ci columns: 5, 209e41f4b71Sopenharmony_ci gutter: { x: 5, y: 10 }, 210e41f4b71Sopenharmony_ci breakpoints: { value: ["400vp", "600vp", "800vp"], 211e41f4b71Sopenharmony_ci reference: BreakpointsReference.WindowSize }, 212e41f4b71Sopenharmony_ci direction: GridRowDirection.Row 213e41f4b71Sopenharmony_ci }) { 214e41f4b71Sopenharmony_ci ForEach(this.bgColors, (color: Color) => { 215e41f4b71Sopenharmony_ci GridCol({ span: { xs: 1, sm: 2, md: 3, lg: 4 }, offset: 0, order: 0 }) { 216e41f4b71Sopenharmony_ci Row().width("100%").height("20vp") 217e41f4b71Sopenharmony_ci }.borderColor(color).borderWidth(2) 218e41f4b71Sopenharmony_ci }) 219e41f4b71Sopenharmony_ci }.width("100%").height("100%") 220e41f4b71Sopenharmony_ci .onBreakpointChange((breakpoint) => { 221e41f4b71Sopenharmony_ci this.currentBp = breakpoint 222e41f4b71Sopenharmony_ci }) 223e41f4b71Sopenharmony_ci }.width('80%').margin({ left: 10, top: 5, bottom: 5 }).height(200) 224e41f4b71Sopenharmony_ci .border({ color: '#880606', width: 2 }) 225e41f4b71Sopenharmony_ci } 226e41f4b71Sopenharmony_ci} 227e41f4b71Sopenharmony_ci``` 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci 230