1e41f4b71Sopenharmony_ci# RelativeContainer 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **RelativeContainer** component is a container component used for relative layout of elements in complex scenarios. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> This component is supported since API version 9. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## Rules 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci * Components in the container are aligned horizontally or vertically. 12e41f4b71Sopenharmony_ci * Alignment modes in the horizontal direction can be left, middle, or right, achieved by the **HorizontalAlign.Start**, **HorizontalAlign.Center**, and **HorizontalAlign.End** attributes of the container, respectively. 13e41f4b71Sopenharmony_ci * Alignment modes in the vertical direction can be top, center, or bottom, achieved by the **VerticalAlign.Top**, **VerticalAlign.Center**, and **VerticalAlign.Bottom** attributes of the container, respectively. 14e41f4b71Sopenharmony_ci * A child component can have the container, a guideline, a barrier, or another child component as the anchor. 15e41f4b71Sopenharmony_ci * If a child component laid out in the container does not have an ID set, it is still visible, but cannot be used as an anchor by other child components. The container automatically sets an ID for such a component, using rules that cannot be detected by applications. The container ID is fixed at **__container__**. The ID of a guideline and barrier cannot be the same as any of the components. If they are the same, the IDs take effect as follows (in descending order of priority): component, guideline, barrier. 16e41f4b71Sopenharmony_ci * A child component can have anchors for three positions in one direction (left, middle, and right in the horizontal direction and top, center, and bottom in the vertical direction). These anchors can be positions in the container or other child components in the same direction: **horizontalAlign.Start**, **HorizontalAlign.Center**, and **HorizontalAlign.End** in the horizontal direction and **verticalAlign.Top**, **VerticalAlign.Center**, and **VerticalAlign.Bottom** in the vertical direction. If more than two anchors are set in the same direction, **Start** and **Center** in the horizontal direction are preferred, and **Top** and **Center** in the vertical direction are preferred. For example, when the left, middle, and right positions of a component in the horizontal direction use **HorizontalAlign.Start**, **HorizontalAlign.Center**, and **HorizontalAlign.End** of the container as the anchors, respectively, then: if the widths of the component and its container cannot meet these rules at the same time, the rules for Start and Center are followed. 17e41f4b71Sopenharmony_ci * If both the child component size and relative layout rules are set:<br>In API versions earlier than 11, the child component size is bound by the relative layout rules.<br> Since API version 11, the child component size set from frontend pages is used. 18e41f4b71Sopenharmony_ci * If offset is required after the alignment, it can be set through [bias](ts-universal-attributes-location.md#bias) (available since API version 11) or **offset** (not recommended). 19e41f4b71Sopenharmony_ci * Since API version 11, if **RelativeContainer** has its **width** and **height** attributes set to **auto**, it adapts its width and height to its child components. 20e41f4b71Sopenharmony_ci * If the container's child component uses the container as an anchor in the horizontal direction, the **auto** value of **width** has no effect. The same rule applies to the vertical direction. 21e41f4b71Sopenharmony_ci * For a child component of the container, **margin** has a different meaning from the universal attribute **margin**. It indicates the distance to the anchor in the respective direction. If there is no anchor in the respective direction, **margin** in that direction does not take effect. 22e41f4b71Sopenharmony_ci * If the position of the guideline is not declared or the declared value (for example, **undefined**) is invalid, the position of **start: 0** is used. Either **start** or **end** can be declared for the position. If both of them are declared, only **start** takes effect. 23e41f4b71Sopenharmony_ci * If the size of the container in a direction is declared as **auto**, the position of guidelines in the direction must be declared in **start** mode (the value cannot be in percentage). 24e41f4b71Sopenharmony_ci * A guideline or barrier in the vertical direction can only be used as the anchor of the component in the horizontal direction, and the value is **0** when it is used as the anchor in the vertical direction. A guideline or barrier in the horizontal direction can only be used as the anchor of the component in the vertical direction, and the value is **0** when it is used as the anchor in the horizontal direction. 25e41f4b71Sopenharmony_ci * The formation of a chain depends on the dependency between components. For example, the minimum horizontal chain formed by component A and component B requires the following dependency: Anchor 1 <- Component A <--> Component B -> Anchor 2. That is, A has a left anchor, B has a right anchor, the right anchor of A is **HorizontalAlign.Start** of B, and the left anchor of B is **HorizontalAlign.End** of A. 26e41f4b71Sopenharmony_ci * The direction and format of the chain are declared in the [chainMode](ts-universal-attributes-location.md#chainmode12) API of the chain head component. The **bias** attributes of all elements in the chain are ineffective, and the bias of the chain head element takes effect as the bias of the entire chain. 27e41f4b71Sopenharmony_ci * If the size of all elements in a chain exceeds the anchor constraint of the chain, the excess part is evenly distributed on both sides of the chain. In the [Packed](ts-appendix-enums.md#chainstyle12) chain, the distribution of the excess part can be set through [bias](ts-universal-attributes-location.md#bias). 28e41f4b71Sopenharmony_ci * Exceptions 29e41f4b71Sopenharmony_ci * If the size of a child component cannot be determined based on the rules and its own **size** attribute, the child component is not drawn. 30e41f4b71Sopenharmony_ci * When a mutual or circular dependency occurs, none of the child components in the container are drawn. 31e41f4b71Sopenharmony_ci * If anchors are set for two or more positions in a single direction but the anchor positions are reversed, the size of the child component is 0, which means that the child component is not drawn. 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci## Child Components 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ciMultiple child components are supported. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci## APIs 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ciRelativeContainer() 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9. 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci## Attributes 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci### guideLine<sup>12+</sup> 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ciguideLine(value: Array<GuideLineStyle>) 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ciSets the guidelines in the **RelativeContainer** component. The value is an array, each element of which is a guideline. 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci**Parameters** 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 61e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | --------------------------------- | 62e41f4b71Sopenharmony_ci| value | Array<[GuideLineStyle](#guidelinestyle12)> | Yes | Guidelines in the **RelativeContainer** component.| 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci### barrier<sup>12+</sup> 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_cibarrier(value: Array<BarrierStyle>) 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ciSets the barriers in the **RelativeContainer** component. The value is an array, each element of which is a barrier. 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci**Parameters** 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 75e41f4b71Sopenharmony_ci| ------ | -------------------------------------- | ---- | ------------------------------- | 76e41f4b71Sopenharmony_ci| value | Array<[BarrierStyle](#barrierstyle12)> | Yes | Barriers in the **RelativeContainer** component.| 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci### barrier<sup>12+</sup> 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_cibarrier(barrierStyle: Array<LocalizedBarrierStyle>) 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ciSets the barriers in the **RelativeContainer** component. The value is an array, each element of which is a barrier. 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci**Parameters** 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 89e41f4b71Sopenharmony_ci| ------ | -------------------------------------- | ---- | ------------------------------ | 90e41f4b71Sopenharmony_ci| barrierStyle | Array\<[LocalizedBarrierStyle](#localizedbarrierstyle12)\> | Yes | Barriers in the **RelativeContainer** component.| 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci## GuideLineStyle<sup>12+</sup> 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ciDefines the ID, direction, and position of a guideline. 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci**Parameters** 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 99e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- | 100e41f4b71Sopenharmony_ci| id | string | Yes | ID of the guideline, which must be unique and cannot be the same as the name of any component in the container. | 101e41f4b71Sopenharmony_ci| direction | [Axis](ts-appendix-enums.md#axis) | Yes | Direction of the guideline.<br>Default value: **Axis.Vertical**| 102e41f4b71Sopenharmony_ci| position | [GuideLinePosition](#guidelineposition12) | Yes | Position of the guideline.<br>Default value:<br>{<br>start: 0<br>} | 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci## GuideLinePosition<sup>12+</sup> 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ciDefines the position of a guideline. 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci**Parameters** 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 111e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- | 112e41f4b71Sopenharmony_ci| start | [Dimension](ts-types.md#dimension10) | No | Distance between the guideline and the left or top of the container. | 113e41f4b71Sopenharmony_ci| end | [Dimension](ts-types.md#dimension10) | No | Distance between the guideline and the right or bottom of the container.| 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci## BarrierStyle<sup>12+</sup> 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ciDefines the ID, direction, and referenced components of a barrier. 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci**Parameters** 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 122e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- | 123e41f4b71Sopenharmony_ci| id | string | Yes | ID of the barrier, which must be unique and cannot be the same as the name of any component in the container. | 124e41f4b71Sopenharmony_ci| direction | [BarrierDirection](ts-appendix-enums.md#barrierdirection12) | Yes | Direction of the barrier.<br>Default value: **BarrierDirection.LEFT**| 125e41f4b71Sopenharmony_ci| referencedId | Array\<string> | Yes | Referenced components of the barrier.| 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci## LocalizedBarrierStyle<sup>12+</sup> 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ciDefines the ID, direction, and referenced components of a barrier. 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci**Parameters** 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 134e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- | 135e41f4b71Sopenharmony_ci| id | string | Yes | ID of the barrier, which must be unique and cannot be the same as the name of any component in the container. | 136e41f4b71Sopenharmony_ci| localizedDirection | [LocalizedBarrierDirection](#localizedbarrierdirection12) | Yes | Direction of the barrier.| 137e41f4b71Sopenharmony_ci| referencedId | Array\<string\> | Yes | Referenced components of the barrier.| 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci## LocalizedBarrierDirection<sup>12+</sup> 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ciDefines the direction of a barrier. 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci| Name| Value | Description | 144e41f4b71Sopenharmony_ci| ------ | -- | ----------------------------- | 145e41f4b71Sopenharmony_ci| START | 0 |The barrier is on the left (for left-to-right scripts) or right (for right-to-left scripts) side of all the referenced components specified by [referencedId](#localizedbarrierstyle12).| 146e41f4b71Sopenharmony_ci| END | 1 | The barrier is on the right (for left-to-right scripts) or left (for right-to-left scripts) side of all the referenced components specified by [referencedId](#localizedbarrierstyle12). | 147e41f4b71Sopenharmony_ci| TOP | 2 | The barrier is at the top of all the referenced components specified by [referencedId](#localizedbarrierstyle12). | 148e41f4b71Sopenharmony_ci| BOTTOM | 3 | The barrier is at the bottom of all the referenced components specified by [referencedId](#localizedbarrierstyle12).| 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci## Example 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci### Example 1 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ciThis example shows how to use containers and components in the containers as anchors for layout. 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci```ts 157e41f4b71Sopenharmony_ci@Entry 158e41f4b71Sopenharmony_ci@Component 159e41f4b71Sopenharmony_cistruct Index { 160e41f4b71Sopenharmony_ci build() { 161e41f4b71Sopenharmony_ci Row() { 162e41f4b71Sopenharmony_ci RelativeContainer() { 163e41f4b71Sopenharmony_ci Row(){Text('row1')}.justifyContent(FlexAlign.Center) 164e41f4b71Sopenharmony_ci .width(100).height(100) 165e41f4b71Sopenharmony_ci .backgroundColor("#FF3333") 166e41f4b71Sopenharmony_ci .alignRules({ 167e41f4b71Sopenharmony_ci top: {anchor: "__container__", align: VerticalAlign.Top}, 168e41f4b71Sopenharmony_ci left: {anchor: "__container__", align: HorizontalAlign.Start} 169e41f4b71Sopenharmony_ci }) 170e41f4b71Sopenharmony_ci .id("row1") 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci Row(){Text('row2')}.justifyContent(FlexAlign.Center) 173e41f4b71Sopenharmony_ci .width(100).height(100) 174e41f4b71Sopenharmony_ci .backgroundColor("#FFCC00") 175e41f4b71Sopenharmony_ci .alignRules({ 176e41f4b71Sopenharmony_ci top: {anchor: "__container__", align: VerticalAlign.Top}, 177e41f4b71Sopenharmony_ci right: {anchor: "__container__", align: HorizontalAlign.End} 178e41f4b71Sopenharmony_ci }) 179e41f4b71Sopenharmony_ci .id("row2") 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci Row(){Text('row3')}.justifyContent(FlexAlign.Center) 182e41f4b71Sopenharmony_ci .height(100) 183e41f4b71Sopenharmony_ci .backgroundColor("#FF6633") 184e41f4b71Sopenharmony_ci .alignRules({ 185e41f4b71Sopenharmony_ci top: {anchor: "row1", align: VerticalAlign.Bottom}, 186e41f4b71Sopenharmony_ci left: {anchor: "row1", align: HorizontalAlign.End}, 187e41f4b71Sopenharmony_ci right: {anchor: "row2", align: HorizontalAlign.Start} 188e41f4b71Sopenharmony_ci }) 189e41f4b71Sopenharmony_ci .id("row3") 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ci Row(){Text('row4')}.justifyContent(FlexAlign.Center) 192e41f4b71Sopenharmony_ci .backgroundColor("#FF9966") 193e41f4b71Sopenharmony_ci .alignRules({ 194e41f4b71Sopenharmony_ci top: {anchor: "row3", align: VerticalAlign.Bottom}, 195e41f4b71Sopenharmony_ci bottom: {anchor: "__container__", align: VerticalAlign.Bottom}, 196e41f4b71Sopenharmony_ci left: {anchor: "__container__", align: HorizontalAlign.Start}, 197e41f4b71Sopenharmony_ci right: {anchor: "row1", align: HorizontalAlign.End} 198e41f4b71Sopenharmony_ci }) 199e41f4b71Sopenharmony_ci .id("row4") 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci Row(){Text('row5')}.justifyContent(FlexAlign.Center) 202e41f4b71Sopenharmony_ci .backgroundColor("#FF66FF") 203e41f4b71Sopenharmony_ci .alignRules({ 204e41f4b71Sopenharmony_ci top: {anchor: "row3", align: VerticalAlign.Bottom}, 205e41f4b71Sopenharmony_ci bottom: {anchor: "__container__", align: VerticalAlign.Bottom}, 206e41f4b71Sopenharmony_ci left: {anchor: "row2", align: HorizontalAlign.Start}, 207e41f4b71Sopenharmony_ci right: {anchor: "__container__", align: HorizontalAlign.End} 208e41f4b71Sopenharmony_ci }) 209e41f4b71Sopenharmony_ci .id("row5") 210e41f4b71Sopenharmony_ci } 211e41f4b71Sopenharmony_ci .width(300).height(300) 212e41f4b71Sopenharmony_ci .margin({left: 50}) 213e41f4b71Sopenharmony_ci .border({width:2, color: "#6699FF"}) 214e41f4b71Sopenharmony_ci } 215e41f4b71Sopenharmony_ci .height('100%') 216e41f4b71Sopenharmony_ci } 217e41f4b71Sopenharmony_ci} 218e41f4b71Sopenharmony_ci``` 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci### Example 2 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ciThis example shows how to set margins for child components in the container. 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci```ts 226e41f4b71Sopenharmony_ci@Entry 227e41f4b71Sopenharmony_ci@Component 228e41f4b71Sopenharmony_cistruct Index { 229e41f4b71Sopenharmony_ci build() { 230e41f4b71Sopenharmony_ci Row() { 231e41f4b71Sopenharmony_ci RelativeContainer() { 232e41f4b71Sopenharmony_ci Row(){Text('row1')}.justifyContent(FlexAlign.Center) 233e41f4b71Sopenharmony_ci .width(100).height(100) 234e41f4b71Sopenharmony_ci .backgroundColor("#FF3333") 235e41f4b71Sopenharmony_ci .alignRules({ 236e41f4b71Sopenharmony_ci top: {anchor: "__container__", align: VerticalAlign.Top}, 237e41f4b71Sopenharmony_ci left: {anchor: "__container__", align: HorizontalAlign.Start} 238e41f4b71Sopenharmony_ci }) 239e41f4b71Sopenharmony_ci .id("row1") 240e41f4b71Sopenharmony_ci .margin(10) 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci Row(){Text('row2')}.justifyContent(FlexAlign.Center) 243e41f4b71Sopenharmony_ci .width(100).height(100) 244e41f4b71Sopenharmony_ci .backgroundColor("#FFCC00") 245e41f4b71Sopenharmony_ci .alignRules({ 246e41f4b71Sopenharmony_ci left: {anchor: "row1", align: HorizontalAlign.End}, 247e41f4b71Sopenharmony_ci top: {anchor: "row1", align: VerticalAlign.Top} 248e41f4b71Sopenharmony_ci }) 249e41f4b71Sopenharmony_ci .id("row2") 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci Row(){Text('row3')}.justifyContent(FlexAlign.Center) 252e41f4b71Sopenharmony_ci .width(100).height(100) 253e41f4b71Sopenharmony_ci .backgroundColor("#FF6633") 254e41f4b71Sopenharmony_ci .alignRules({ 255e41f4b71Sopenharmony_ci left: {anchor: "row1", align: HorizontalAlign.Start}, 256e41f4b71Sopenharmony_ci top: {anchor: "row1", align: VerticalAlign.Bottom} 257e41f4b71Sopenharmony_ci }) 258e41f4b71Sopenharmony_ci .id("row3") 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ci Row(){Text('row4')}.justifyContent(FlexAlign.Center) 261e41f4b71Sopenharmony_ci .width(100).height(100) 262e41f4b71Sopenharmony_ci .backgroundColor("#FF9966") 263e41f4b71Sopenharmony_ci .alignRules({ 264e41f4b71Sopenharmony_ci left: {anchor: "row3", align: HorizontalAlign.End}, 265e41f4b71Sopenharmony_ci top: {anchor: "row2", align: VerticalAlign.Bottom} 266e41f4b71Sopenharmony_ci }) 267e41f4b71Sopenharmony_ci .id("row4") 268e41f4b71Sopenharmony_ci .margin(10) 269e41f4b71Sopenharmony_ci } 270e41f4b71Sopenharmony_ci .width(300).height(300) 271e41f4b71Sopenharmony_ci .margin({left: 50}) 272e41f4b71Sopenharmony_ci .border({width:2, color: "#6699FF"}) 273e41f4b71Sopenharmony_ci } 274e41f4b71Sopenharmony_ci .height('100%') 275e41f4b71Sopenharmony_ci } 276e41f4b71Sopenharmony_ci} 277e41f4b71Sopenharmony_ci``` 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci### Example 3 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ciThis example shows how to configure the container to adapt its size to content (**size** declared as **"auto"**). 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci```ts 285e41f4b71Sopenharmony_ci@Entry 286e41f4b71Sopenharmony_ci@Component 287e41f4b71Sopenharmony_cistruct Index { 288e41f4b71Sopenharmony_ci build() { 289e41f4b71Sopenharmony_ci Row() { 290e41f4b71Sopenharmony_ci RelativeContainer() { 291e41f4b71Sopenharmony_ci Row(){Text('row1')}.justifyContent(FlexAlign.Center) 292e41f4b71Sopenharmony_ci .width(100).height(100) 293e41f4b71Sopenharmony_ci .backgroundColor("#FF3333") 294e41f4b71Sopenharmony_ci .id("row1") 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci Row(){Text('row2')}.justifyContent(FlexAlign.Center) 297e41f4b71Sopenharmony_ci .width(100).height(100) 298e41f4b71Sopenharmony_ci .backgroundColor("#FFCC00") 299e41f4b71Sopenharmony_ci .alignRules({ 300e41f4b71Sopenharmony_ci left: {anchor: "row1", align: HorizontalAlign.End}, 301e41f4b71Sopenharmony_ci top: {anchor: "row1", align: VerticalAlign.Top} 302e41f4b71Sopenharmony_ci }) 303e41f4b71Sopenharmony_ci .id("row2") 304e41f4b71Sopenharmony_ci 305e41f4b71Sopenharmony_ci Row(){Text('row3')}.justifyContent(FlexAlign.Center) 306e41f4b71Sopenharmony_ci .width(100).height(100) 307e41f4b71Sopenharmony_ci .backgroundColor("#FF6633") 308e41f4b71Sopenharmony_ci .alignRules({ 309e41f4b71Sopenharmony_ci left: {anchor: "row1", align: HorizontalAlign.Start}, 310e41f4b71Sopenharmony_ci top: {anchor: "row1", align: VerticalAlign.Bottom} 311e41f4b71Sopenharmony_ci }) 312e41f4b71Sopenharmony_ci .id("row3") 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci Row(){Text('row4')}.justifyContent(FlexAlign.Center) 315e41f4b71Sopenharmony_ci .width(100).height(100) 316e41f4b71Sopenharmony_ci .backgroundColor("#FF9966") 317e41f4b71Sopenharmony_ci .alignRules({ 318e41f4b71Sopenharmony_ci left: {anchor: "row3", align: HorizontalAlign.End}, 319e41f4b71Sopenharmony_ci top: {anchor: "row2", align: VerticalAlign.Bottom} 320e41f4b71Sopenharmony_ci }) 321e41f4b71Sopenharmony_ci .id("row4") 322e41f4b71Sopenharmony_ci } 323e41f4b71Sopenharmony_ci .width("auto").height("auto") 324e41f4b71Sopenharmony_ci .margin({left: 50}) 325e41f4b71Sopenharmony_ci .border({width:2, color: "#6699FF"}) 326e41f4b71Sopenharmony_ci } 327e41f4b71Sopenharmony_ci .height('100%') 328e41f4b71Sopenharmony_ci } 329e41f4b71Sopenharmony_ci} 330e41f4b71Sopenharmony_ci``` 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci 333e41f4b71Sopenharmony_ci### Example 4 334e41f4b71Sopenharmony_ci 335e41f4b71Sopenharmony_ciThis example shows the usage of **bias**. 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ci```ts 338e41f4b71Sopenharmony_ci@Entry 339e41f4b71Sopenharmony_ci@Component 340e41f4b71Sopenharmony_cistruct Index { 341e41f4b71Sopenharmony_ci build() { 342e41f4b71Sopenharmony_ci Row() { 343e41f4b71Sopenharmony_ci RelativeContainer() { 344e41f4b71Sopenharmony_ci Row().width(100).height(100) 345e41f4b71Sopenharmony_ci .backgroundColor("#FF3333") 346e41f4b71Sopenharmony_ci .alignRules({ 347e41f4b71Sopenharmony_ci top: {anchor: "__container__", align: VerticalAlign.Top}, 348e41f4b71Sopenharmony_ci bottom : {anchor : "__container__", align : VerticalAlign.Bottom}, 349e41f4b71Sopenharmony_ci left: {anchor: "__container__", align: HorizontalAlign.Start}, 350e41f4b71Sopenharmony_ci right : {anchor : "__container__", align: HorizontalAlign.End}, 351e41f4b71Sopenharmony_ci bias : {vertical : 0.3} 352e41f4b71Sopenharmony_ci }) 353e41f4b71Sopenharmony_ci .id("row1") 354e41f4b71Sopenharmony_ci } 355e41f4b71Sopenharmony_ci .width(300).height(300) 356e41f4b71Sopenharmony_ci .margin({left: 50}) 357e41f4b71Sopenharmony_ci .border({width:2, color: "#6699FF"}) 358e41f4b71Sopenharmony_ci } 359e41f4b71Sopenharmony_ci .height('100%') 360e41f4b71Sopenharmony_ci } 361e41f4b71Sopenharmony_ci} 362e41f4b71Sopenharmony_ci``` 363e41f4b71Sopenharmony_ci 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci### Example 5 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ciThis example shows how to declare a guideline and use it as an anchor. 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci```ts 370e41f4b71Sopenharmony_ci@Entry 371e41f4b71Sopenharmony_ci@Component 372e41f4b71Sopenharmony_cistruct Index { 373e41f4b71Sopenharmony_ci build() { 374e41f4b71Sopenharmony_ci Row() { 375e41f4b71Sopenharmony_ci RelativeContainer() { 376e41f4b71Sopenharmony_ci Row().width(100).height(100) 377e41f4b71Sopenharmony_ci .backgroundColor("#FF3333") 378e41f4b71Sopenharmony_ci .alignRules({ 379e41f4b71Sopenharmony_ci left: {anchor: "guideline1", align: HorizontalAlign.End}, 380e41f4b71Sopenharmony_ci top: {anchor: "guideline2", align: VerticalAlign.Top} 381e41f4b71Sopenharmony_ci }) 382e41f4b71Sopenharmony_ci .id("row1") 383e41f4b71Sopenharmony_ci } 384e41f4b71Sopenharmony_ci .width(300).height(300) 385e41f4b71Sopenharmony_ci .margin({left: 50}) 386e41f4b71Sopenharmony_ci .border({width:2, color: "#6699FF"}) 387e41f4b71Sopenharmony_ci .guideLine([{id:"guideline1", direction: Axis.Vertical, position:{start:50}}, 388e41f4b71Sopenharmony_ci {id:"guideline2", direction: Axis.Horizontal, position:{start:50}}]) 389e41f4b71Sopenharmony_ci } 390e41f4b71Sopenharmony_ci .height('100%') 391e41f4b71Sopenharmony_ci } 392e41f4b71Sopenharmony_ci} 393e41f4b71Sopenharmony_ci``` 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ci 396e41f4b71Sopenharmony_ci### Example 6 397e41f4b71Sopenharmony_ci 398e41f4b71Sopenharmony_ciThis example shows how to declare a barrier and use it as an anchor. 399e41f4b71Sopenharmony_ci 400e41f4b71Sopenharmony_ci```ts 401e41f4b71Sopenharmony_ci@Entry 402e41f4b71Sopenharmony_ci@Component 403e41f4b71Sopenharmony_cistruct Index { 404e41f4b71Sopenharmony_ci build() { 405e41f4b71Sopenharmony_ci Row() { 406e41f4b71Sopenharmony_ci RelativeContainer() { 407e41f4b71Sopenharmony_ci Row(){Text('row1')}.justifyContent(FlexAlign.Center) 408e41f4b71Sopenharmony_ci .width(100).height(100) 409e41f4b71Sopenharmony_ci .backgroundColor("#FF3333") 410e41f4b71Sopenharmony_ci .id("row1") 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci Row(){Text('row2')}.justifyContent(FlexAlign.Center) 413e41f4b71Sopenharmony_ci .width(100).height(100) 414e41f4b71Sopenharmony_ci .backgroundColor("#FFCC00") 415e41f4b71Sopenharmony_ci .alignRules({ 416e41f4b71Sopenharmony_ci middle: {anchor: "row1", align: HorizontalAlign.End}, 417e41f4b71Sopenharmony_ci top: {anchor: "row1", align: VerticalAlign.Bottom} 418e41f4b71Sopenharmony_ci }) 419e41f4b71Sopenharmony_ci .id("row2") 420e41f4b71Sopenharmony_ci 421e41f4b71Sopenharmony_ci Row(){Text('row3')}.justifyContent(FlexAlign.Center) 422e41f4b71Sopenharmony_ci .width(100).height(100) 423e41f4b71Sopenharmony_ci .backgroundColor("#FF6633") 424e41f4b71Sopenharmony_ci .alignRules({ 425e41f4b71Sopenharmony_ci left: {anchor: "barrier1", align: HorizontalAlign.End}, 426e41f4b71Sopenharmony_ci top: {anchor: "row1", align: VerticalAlign.Top} 427e41f4b71Sopenharmony_ci }) 428e41f4b71Sopenharmony_ci .id("row3") 429e41f4b71Sopenharmony_ci 430e41f4b71Sopenharmony_ci Row(){Text('row4')}.justifyContent(FlexAlign.Center) 431e41f4b71Sopenharmony_ci .width(50).height(50) 432e41f4b71Sopenharmony_ci .backgroundColor("#FF9966") 433e41f4b71Sopenharmony_ci .alignRules({ 434e41f4b71Sopenharmony_ci left: {anchor: "row1", align: HorizontalAlign.Start}, 435e41f4b71Sopenharmony_ci top: {anchor: "barrier2", align: VerticalAlign.Bottom} 436e41f4b71Sopenharmony_ci }) 437e41f4b71Sopenharmony_ci .id("row4") 438e41f4b71Sopenharmony_ci } 439e41f4b71Sopenharmony_ci .width(300).height(300) 440e41f4b71Sopenharmony_ci .margin({left: 50}) 441e41f4b71Sopenharmony_ci .border({width:2, color: "#6699FF"}) 442e41f4b71Sopenharmony_ci .barrier([{id: "barrier1", direction: BarrierDirection.RIGHT, referencedId:["row1", "row2"]}, 443e41f4b71Sopenharmony_ci {id: "barrier2", direction: BarrierDirection.BOTTOM, referencedId:["row1", "row2"]}]) 444e41f4b71Sopenharmony_ci } 445e41f4b71Sopenharmony_ci .height('100%') 446e41f4b71Sopenharmony_ci } 447e41f4b71Sopenharmony_ci} 448e41f4b71Sopenharmony_ci``` 449e41f4b71Sopenharmony_ci 450e41f4b71Sopenharmony_ci 451e41f4b71Sopenharmony_ci### Example 7 452e41f4b71Sopenharmony_ci 453e41f4b71Sopenharmony_ciThis example demonstrates the implementation of horizontal **SPREAD** chain, **SPREAD_INSIDE** chain, and **PACKED** chain from top to bottom using the **chainMode** API. 454e41f4b71Sopenharmony_ci 455e41f4b71Sopenharmony_ci```ts 456e41f4b71Sopenharmony_ci@Entry 457e41f4b71Sopenharmony_ci@Component 458e41f4b71Sopenharmony_cistruct Index { 459e41f4b71Sopenharmony_ci build() { 460e41f4b71Sopenharmony_ci Row() { 461e41f4b71Sopenharmony_ci RelativeContainer() { 462e41f4b71Sopenharmony_ci Row(){Text('row1')}.justifyContent(FlexAlign.Center) 463e41f4b71Sopenharmony_ci .width(80).height(80) 464e41f4b71Sopenharmony_ci .backgroundColor("#FF3333") 465e41f4b71Sopenharmony_ci .alignRules({ 466e41f4b71Sopenharmony_ci left: {anchor: "__container__", align: HorizontalAlign.Start}, 467e41f4b71Sopenharmony_ci right: {anchor: "row2", align : HorizontalAlign.Start}, 468e41f4b71Sopenharmony_ci top: {anchor: "__container__", align: VerticalAlign.Top} 469e41f4b71Sopenharmony_ci }) 470e41f4b71Sopenharmony_ci .id("row1") 471e41f4b71Sopenharmony_ci .chainMode(Axis.Horizontal, ChainStyle.SPREAD) 472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci Row(){Text('row2')}.justifyContent(FlexAlign.Center) 474e41f4b71Sopenharmony_ci .width(80).height(80) 475e41f4b71Sopenharmony_ci .backgroundColor("#FFCC00") 476e41f4b71Sopenharmony_ci .alignRules({ 477e41f4b71Sopenharmony_ci left: {anchor: "row1", align: HorizontalAlign.End}, 478e41f4b71Sopenharmony_ci right: {anchor: "row3", align : HorizontalAlign.Start}, 479e41f4b71Sopenharmony_ci top: {anchor: "row1", align: VerticalAlign.Top} 480e41f4b71Sopenharmony_ci }) 481e41f4b71Sopenharmony_ci .id("row2") 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci Row(){Text('row3')}.justifyContent(FlexAlign.Center) 484e41f4b71Sopenharmony_ci .width(80).height(80) 485e41f4b71Sopenharmony_ci .backgroundColor("#FF6633") 486e41f4b71Sopenharmony_ci .alignRules({ 487e41f4b71Sopenharmony_ci left: {anchor: "row2", align: HorizontalAlign.End}, 488e41f4b71Sopenharmony_ci right: {anchor: "__container__", align : HorizontalAlign.End}, 489e41f4b71Sopenharmony_ci top: {anchor: "row1", align: VerticalAlign.Top} 490e41f4b71Sopenharmony_ci }) 491e41f4b71Sopenharmony_ci .id("row3") 492e41f4b71Sopenharmony_ci 493e41f4b71Sopenharmony_ci Row(){Text('row4')}.justifyContent(FlexAlign.Center) 494e41f4b71Sopenharmony_ci .width(80).height(80) 495e41f4b71Sopenharmony_ci .backgroundColor("#FF3333") 496e41f4b71Sopenharmony_ci .alignRules({ 497e41f4b71Sopenharmony_ci left: {anchor: "__container__", align: HorizontalAlign.Start}, 498e41f4b71Sopenharmony_ci right: {anchor: "row5", align : HorizontalAlign.Start}, 499e41f4b71Sopenharmony_ci center: {anchor: "__container__", align: VerticalAlign.Center} 500e41f4b71Sopenharmony_ci }) 501e41f4b71Sopenharmony_ci .id("row4") 502e41f4b71Sopenharmony_ci .chainMode(Axis.Horizontal, ChainStyle.SPREAD_INSIDE) 503e41f4b71Sopenharmony_ci 504e41f4b71Sopenharmony_ci Row(){Text('row5')}.justifyContent(FlexAlign.Center) 505e41f4b71Sopenharmony_ci .width(80).height(80) 506e41f4b71Sopenharmony_ci .backgroundColor("#FFCC00") 507e41f4b71Sopenharmony_ci .alignRules({ 508e41f4b71Sopenharmony_ci left: {anchor: "row4", align: HorizontalAlign.End}, 509e41f4b71Sopenharmony_ci right: {anchor: "row6", align : HorizontalAlign.Start}, 510e41f4b71Sopenharmony_ci top: {anchor: "row4", align: VerticalAlign.Top} 511e41f4b71Sopenharmony_ci }) 512e41f4b71Sopenharmony_ci .id("row5") 513e41f4b71Sopenharmony_ci 514e41f4b71Sopenharmony_ci Row(){Text('row6')}.justifyContent(FlexAlign.Center) 515e41f4b71Sopenharmony_ci .width(80).height(80) 516e41f4b71Sopenharmony_ci .backgroundColor("#FF6633") 517e41f4b71Sopenharmony_ci .alignRules({ 518e41f4b71Sopenharmony_ci left: {anchor: "row5", align: HorizontalAlign.End}, 519e41f4b71Sopenharmony_ci right: {anchor: "__container__", align : HorizontalAlign.End}, 520e41f4b71Sopenharmony_ci top: {anchor: "row4", align: VerticalAlign.Top} 521e41f4b71Sopenharmony_ci }) 522e41f4b71Sopenharmony_ci .id("row6") 523e41f4b71Sopenharmony_ci 524e41f4b71Sopenharmony_ci Row(){Text('row7')}.justifyContent(FlexAlign.Center) 525e41f4b71Sopenharmony_ci .width(80).height(80) 526e41f4b71Sopenharmony_ci .backgroundColor("#FF3333") 527e41f4b71Sopenharmony_ci .alignRules({ 528e41f4b71Sopenharmony_ci left: {anchor: "__container__", align: HorizontalAlign.Start}, 529e41f4b71Sopenharmony_ci right: {anchor: "row8", align : HorizontalAlign.Start}, 530e41f4b71Sopenharmony_ci bottom: {anchor: "__container__", align: VerticalAlign.Bottom} 531e41f4b71Sopenharmony_ci }) 532e41f4b71Sopenharmony_ci .id("row7") 533e41f4b71Sopenharmony_ci .chainMode(Axis.Horizontal, ChainStyle.PACKED) 534e41f4b71Sopenharmony_ci 535e41f4b71Sopenharmony_ci Row(){Text('row8')}.justifyContent(FlexAlign.Center) 536e41f4b71Sopenharmony_ci .width(80).height(80) 537e41f4b71Sopenharmony_ci .backgroundColor("#FFCC00") 538e41f4b71Sopenharmony_ci .alignRules({ 539e41f4b71Sopenharmony_ci left: {anchor: "row7", align: HorizontalAlign.End}, 540e41f4b71Sopenharmony_ci right: {anchor: "row9", align : HorizontalAlign.Start}, 541e41f4b71Sopenharmony_ci top: {anchor: "row7", align: VerticalAlign.Top} 542e41f4b71Sopenharmony_ci }) 543e41f4b71Sopenharmony_ci .id("row8") 544e41f4b71Sopenharmony_ci 545e41f4b71Sopenharmony_ci Row(){Text('row9')}.justifyContent(FlexAlign.Center) 546e41f4b71Sopenharmony_ci .width(80).height(80) 547e41f4b71Sopenharmony_ci .backgroundColor("#FF6633") 548e41f4b71Sopenharmony_ci .alignRules({ 549e41f4b71Sopenharmony_ci left: {anchor: "row8", align: HorizontalAlign.End}, 550e41f4b71Sopenharmony_ci right: {anchor: "__container__", align : HorizontalAlign.End}, 551e41f4b71Sopenharmony_ci top: {anchor: "row7", align: VerticalAlign.Top} 552e41f4b71Sopenharmony_ci }) 553e41f4b71Sopenharmony_ci .id("row9") 554e41f4b71Sopenharmony_ci } 555e41f4b71Sopenharmony_ci .width(300).height(300) 556e41f4b71Sopenharmony_ci .margin({left: 50}) 557e41f4b71Sopenharmony_ci .border({width:2, color: "#6699FF"}) 558e41f4b71Sopenharmony_ci } 559e41f4b71Sopenharmony_ci .height('100%') 560e41f4b71Sopenharmony_ci } 561e41f4b71Sopenharmony_ci} 562e41f4b71Sopenharmony_ci``` 563e41f4b71Sopenharmony_ci 564e41f4b71Sopenharmony_ci 565e41f4b71Sopenharmony_ci### Example 8 566e41f4b71Sopenharmony_ci 567e41f4b71Sopenharmony_ciThis example shows how to use **chainMode** and **bias** to implement the horizontal **PACKED** chain with a bias. 568e41f4b71Sopenharmony_ci 569e41f4b71Sopenharmony_ci```ts 570e41f4b71Sopenharmony_ci@Entry 571e41f4b71Sopenharmony_ci@Component 572e41f4b71Sopenharmony_cistruct Index { 573e41f4b71Sopenharmony_ci build() { 574e41f4b71Sopenharmony_ci Row() { 575e41f4b71Sopenharmony_ci RelativeContainer() { 576e41f4b71Sopenharmony_ci Row(){Text('row1')}.justifyContent(FlexAlign.Center) 577e41f4b71Sopenharmony_ci .width(80).height(80) 578e41f4b71Sopenharmony_ci .backgroundColor("#FF3333") 579e41f4b71Sopenharmony_ci .alignRules({ 580e41f4b71Sopenharmony_ci left: {anchor: "__container__", align: HorizontalAlign.Start}, 581e41f4b71Sopenharmony_ci right: {anchor: "row2", align : HorizontalAlign.Start}, 582e41f4b71Sopenharmony_ci center: {anchor: "__container__", align: VerticalAlign.Center}, 583e41f4b71Sopenharmony_ci bias : {horizontal : 0} 584e41f4b71Sopenharmony_ci }) 585e41f4b71Sopenharmony_ci .id("row1") 586e41f4b71Sopenharmony_ci .chainMode(Axis.Horizontal, ChainStyle.PACKED) 587e41f4b71Sopenharmony_ci 588e41f4b71Sopenharmony_ci Row(){Text('row2')}.justifyContent(FlexAlign.Center) 589e41f4b71Sopenharmony_ci .width(80).height(80) 590e41f4b71Sopenharmony_ci .backgroundColor("#FFCC00") 591e41f4b71Sopenharmony_ci .alignRules({ 592e41f4b71Sopenharmony_ci left: {anchor: "row1", align: HorizontalAlign.End}, 593e41f4b71Sopenharmony_ci right: {anchor: "row3", align : HorizontalAlign.Start}, 594e41f4b71Sopenharmony_ci top: {anchor: "row1", align: VerticalAlign.Top} 595e41f4b71Sopenharmony_ci }) 596e41f4b71Sopenharmony_ci .id("row2") 597e41f4b71Sopenharmony_ci 598e41f4b71Sopenharmony_ci Row(){Text('row3')}.justifyContent(FlexAlign.Center) 599e41f4b71Sopenharmony_ci .width(80).height(80) 600e41f4b71Sopenharmony_ci .backgroundColor("#FF6633") 601e41f4b71Sopenharmony_ci .alignRules({ 602e41f4b71Sopenharmony_ci left: {anchor: "row2", align: HorizontalAlign.End}, 603e41f4b71Sopenharmony_ci right: {anchor: "__container__", align : HorizontalAlign.End}, 604e41f4b71Sopenharmony_ci top: {anchor: "row1", align: VerticalAlign.Top} 605e41f4b71Sopenharmony_ci }) 606e41f4b71Sopenharmony_ci .id("row3") 607e41f4b71Sopenharmony_ci } 608e41f4b71Sopenharmony_ci .width(300).height(300) 609e41f4b71Sopenharmony_ci .margin({left: 50}) 610e41f4b71Sopenharmony_ci .border({width:2, color: "#6699FF"}) 611e41f4b71Sopenharmony_ci } 612e41f4b71Sopenharmony_ci .height('100%') 613e41f4b71Sopenharmony_ci } 614e41f4b71Sopenharmony_ci} 615e41f4b71Sopenharmony_ci``` 616e41f4b71Sopenharmony_ci 617e41f4b71Sopenharmony_ci 618e41f4b71Sopenharmony_ci### Example 9 619e41f4b71Sopenharmony_ci 620e41f4b71Sopenharmony_ciThis example shows how to use **LocalizedAlignRuleOptions** and **LocalizedBarrierDirection** to set the alignment mode when the barrier is used as the anchor point with right-to-left scripts. 621e41f4b71Sopenharmony_ci 622e41f4b71Sopenharmony_ci```ts 623e41f4b71Sopenharmony_ci@Entry 624e41f4b71Sopenharmony_ci@Component 625e41f4b71Sopenharmony_cistruct Index { 626e41f4b71Sopenharmony_ci build() { 627e41f4b71Sopenharmony_ci Row() { 628e41f4b71Sopenharmony_ci RelativeContainer() { 629e41f4b71Sopenharmony_ci Row(){Text('row1')}.justifyContent(FlexAlign.Center) 630e41f4b71Sopenharmony_ci .width(100).height(100) 631e41f4b71Sopenharmony_ci .backgroundColor("#FF3333") 632e41f4b71Sopenharmony_ci .id("row1") 633e41f4b71Sopenharmony_ci 634e41f4b71Sopenharmony_ci Row(){Text('row2')}.justifyContent(FlexAlign.Center) 635e41f4b71Sopenharmony_ci .width(100).height(100) 636e41f4b71Sopenharmony_ci .backgroundColor("#FFCC00") 637e41f4b71Sopenharmony_ci .alignRules({ 638e41f4b71Sopenharmony_ci middle: {anchor: "row1", align: HorizontalAlign.End}, 639e41f4b71Sopenharmony_ci top: {anchor: "row1", align: VerticalAlign.Bottom} 640e41f4b71Sopenharmony_ci }) 641e41f4b71Sopenharmony_ci .id("row2") 642e41f4b71Sopenharmony_ci 643e41f4b71Sopenharmony_ci Row(){Text('row3')}.justifyContent(FlexAlign.Center) 644e41f4b71Sopenharmony_ci .width(100).height(100) 645e41f4b71Sopenharmony_ci .backgroundColor("#FF6633") 646e41f4b71Sopenharmony_ci .alignRules({ 647e41f4b71Sopenharmony_ci start: {anchor: "barrier1", align: HorizontalAlign.End}, 648e41f4b71Sopenharmony_ci top: {anchor: "row1", align: VerticalAlign.Top} 649e41f4b71Sopenharmony_ci }) 650e41f4b71Sopenharmony_ci .id("row3") 651e41f4b71Sopenharmony_ci 652e41f4b71Sopenharmony_ci Row(){Text('row4')}.justifyContent(FlexAlign.Center) 653e41f4b71Sopenharmony_ci .width(50).height(50) 654e41f4b71Sopenharmony_ci .backgroundColor("#FF9966") 655e41f4b71Sopenharmony_ci .alignRules({ 656e41f4b71Sopenharmony_ci start: {anchor: "row1", align: HorizontalAlign.Start}, 657e41f4b71Sopenharmony_ci top: {anchor: "barrier2", align: VerticalAlign.Bottom} 658e41f4b71Sopenharmony_ci }) 659e41f4b71Sopenharmony_ci .id("row4") 660e41f4b71Sopenharmony_ci } 661e41f4b71Sopenharmony_ci .direction(Direction.Rtl) 662e41f4b71Sopenharmony_ci .width(300).height(300) 663e41f4b71Sopenharmony_ci .margin({left: 50}) 664e41f4b71Sopenharmony_ci .border({width:2, color: "#6699FF"}) 665e41f4b71Sopenharmony_ci .barrier([{id: "barrier1", localizedDirection: LocalizedBarrierDirection.END, referencedId:["row1", "row2"]}, 666e41f4b71Sopenharmony_ci {id: "barrier2", localizedDirection: LocalizedBarrierDirection.BOTTOM, referencedId:["row1", "row2"]}]) 667e41f4b71Sopenharmony_ci } 668e41f4b71Sopenharmony_ci .height('100%') 669e41f4b71Sopenharmony_ci } 670e41f4b71Sopenharmony_ci} 671e41f4b71Sopenharmony_ci``` 672e41f4b71Sopenharmony_ci 673