1# GridRow 2 3The 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. 4 5The **\<GridRow>** component is used in a grid layout, together with its child component [\<GridCol>](ts-container-gridcol.md). 6 7> **NOTE** 8> 9> This component is supported since API version 9. Updates will be marked with a superscript to indicate their earliest API version. 10 11 12## Child Components 13 14This component can contain the **\<GridCol>** child component. 15 16 17## APIs 18GridRow(option?: {columns?: number | GridRowColumnOption, gutter?: Length | GutterOption, breakpoints?: BreakPoints, direction?: GridRowDirection}) 19 20Since API version 9, this API is supported in ArkTS widgets. 21 22**Parameters** 23 24| Name|Type|Mandatory|Description| 25|-----|-----|----|----| 26|columns| number \| [GridRowColumnOption](#gridrowcolumnoption) | No |Number of columns in the grid layout.| 27|gutter|[Length](ts-types.md#length) \| [GutterOption](#gutteroption)| No |Gutter of the grid layout.| 28|breakpoints|[BreakPoints](#breakpoints)| No |Array of breakpoints for the breakpoint value and the corresponding reference based on the window or container size.| 29|direction|[GridRowDirection](#gridrowdirection)| No |Arrangement direction of the grid layout.| 30 31## GutterOption 32 33Provides the gutter options for the grid layout to define the spacing between child components in different directions. 34 35Since API version 9, this API is supported in ArkTS widgets. 36 37| Name | Type | Mandatory | Description | 38| ----- | ------ | ---- | ---------------------------------------- | 39| x | [Length](ts-types.md#length) \| [GridRowSizeOption](#gridrowsizeoption) | No | Horizontal spacing between grid child components. | 40| y | [Length](ts-types.md#length) \| [GridRowSizeOption](#gridrowsizeoption) | No | Vertical spacing between grid child components. | 41 42## GridRowColumnOption 43 44Describes the numbers of grid columns for devices with different grid sizes. 45 46Since API version 9, this API is supported in ArkTS widgets. 47 48| Name | Type | Mandatory | Description | 49| ----- | ------ | ---- | ---------------------------------------- | 50| xs | number | No | Number of grid columns on the device where the grid size is xs. | 51| sm | number | No | Number of grid columns on the device where the grid size is sm. | 52| md | number | No | Number of grid columns on the device where the grid size is md. | 53| lg | number | No | Number of grid columns on the device where the grid size is lg. | 54| xl | number | No | Number of grid columns on the device where the grid size is xl. | 55| xxl | number | No | Number of grid columns on the device where the grid size is xxl. | 56 57**NOTE** 58 59In 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. 60|Breakpoint|Value Range| 61|---|-----------| 62|xs |[0, n0) | 63|sm |[n0, n1) | 64|md |[n1, n2) | 65|lg |[n2, n3) | 66|xl |[n3, n4) | 67|xxl|[n4, INF) | 68 69## GridRowSizeOption 70 71Describes the gutter sizes for different device width types. 72 73Since API version 9, this API is supported in ArkTS widgets. 74 75| Name | Type | Mandatory | Description | 76| ----- | ------ | ---- | ---------------------------------------- | 77| xs | [Length](ts-types.md#length) | No | Gutter size for minimum device width. | 78| sm | [Length](ts-types.md#length) | No | Gutter size for small device width. | 79| md | [Length](ts-types.md#length) | No | Gutter size for medium device width. | 80| lg | [Length](ts-types.md#length) | No | Gutter size for large device width. | 81| xl | [Length](ts-types.md#length) | No | Gutter size for extra large device width. | 82| xxl | [Length](ts-types.md#length) | No | Gutter size for extra extra large device width. | 83 84## BreakPoints 85 86Sets breakpoints for the responsive grid container. 87 88Since API version 9, this API is supported in ArkTS widgets. 89 90| Name | Type | Mandatory | Description | 91| ----- | ------ | ---- | ---------------------------------------- | 92| value | Array<string> | No | Array of monotonically increasing breakpoints.<br>Default value: **["320vp", "600vp", "840vp"]** | 93| reference | [BreakpointsReference](#breakpointsreference) | No | Breakpoint switching reference.<br>Default value: **BreakpointsReference.WindowSize**| 94```ts 95 // Enable the xs, sm, and md breakpoints. 96 breakpoints: {value: ["100vp", "200vp"]} 97 // Enable four breakpoints: xs, sm, md, and lg. The breakpoint range must be monotonically increasing. 98 breakpoints: {value: ["320vp", "600vp", "840vp"]} 99 // Enable five breakpoints: xs, sm, md, lg, and xl. The number of breakpoint ranges cannot exceed the number of breakpoints minus 1. 100 breakpoints: {value: ["320vp", "600vp", "840vp", "1080vp"]} 101``` 102 103## BreakpointsReference 104 105Since API version 9, this API is supported in ArkTS widgets. 106 107| Name| Description| 108| -------- | -------- | 109| WindowSize | The window is used as a reference.| 110| ComponentSize | The container is used as a reference.| 111 112## GridRowDirection 113 114Since API version 9, this API is supported in ArkTS widgets. 115 116| Name| Description| 117| -------- | -------- | 118| Row | Grid elements are arranged in the row direction.| 119| RowReverse | Grid elements are arranged in the reverse row direction.| 120 121**NOTE** 122* Grid elements can be arranged only in the **Row** or **RowReverse** direction, but not in the **Column** or **ColumnReverse** direction. 123* 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. 124* If the **span** value of a single child component exceeds the maximum number of columns, the maximum number of columns is used. 125* 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. 126* Below is the display effect of **Item1: GridCol({span: 6}), Item2: GridCol({ span: 8, offset:11})**. 127 128|1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 129| ----- | ------ | ---- | ---- | -----|-----|---------|--------|------|------- |------- |------- | 130| $\circ$ | $\circ$ | $\circ$ | $\circ$ | $\circ$|$\circ$| - | - | - | - | - | - | 131| - | - | - | - | - | | | | | | | | 132| $\circ$ | $\circ$ | $\circ$ | $\circ$ | $\circ$|$\circ$|$\circ$|$\circ$| | | | | 133 134## Attributes 135 136In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. 137 138| Name | Type | Description | 139| ----------------------- | ----------------------------------- | ------------------------------------------- | 140| alignItems<sup>10+</sup> | ItemAlign | Alignment mode of the **\<GridCol>** cross axis.<br>Default value: **ItemAlign.Start**<br>**NOTE**<br>**ItemAlign** supports the following enums: **ItemAlign.Start**, **ItemAlign.Center**, **ItemAlign.End**, and **ItemAlign.Stretch**.<br>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.<br>Since API version 10, this API is supported in ArkTS widgets.| 141 142 143## Events 144 145### onBreakpointChange 146 147onBreakpointChange(callback: (breakpoints: string) => void) 148 149Triggered when the breakpoint changes. 150 151Since API version 9, this API is supported in ArkTS widgets. 152 153**Parameters** 154 155| Name | Type | Mandatory | Description | 156| ----- | ------ | ---- | ---------------------------------------- | 157|breakpoints| string |No|Breakpoint change.<br> The value can be **"xs"**, **"sm"**, **"md"**, **"lg"**, **"xl"**, or **"xxl"**.| 158 159## Example 160 161```ts 162// xxx.ets 163@Entry 164@Component 165struct GridRowExample { 166 @State bgColors: Color[] = [Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Pink, Color.Grey, Color.Blue, Color.Brown] 167 @State currentBp: string = 'unknown' 168 169 build() { 170 Column() { 171 GridRow({ 172 columns: 5, 173 gutter: { x: 5, y: 10 }, 174 breakpoints: { value: ["400vp", "600vp", "800vp"], 175 reference: BreakpointsReference.WindowSize }, 176 direction: GridRowDirection.Row 177 }) { 178 ForEach(this.bgColors, (color: Color) => { 179 GridCol({ span: { xs: 1, sm: 2, md: 3, lg: 4 }, offset: 0, order: 0 }) { 180 Row().width("100%").height("20vp") 181 }.borderColor(color).borderWidth(2) 182 }) 183 }.width("100%").height("100%") 184 .onBreakpointChange((breakpoint) => { 185 this.currentBp = breakpoint 186 }) 187 }.width('80%').margin({ left: 10, top: 5, bottom: 5 }).height(200) 188 .border({ color: '#880606', width: 2 }) 189 } 190} 191``` 192 193 194