1e41f4b71Sopenharmony_ci# RelativeContainer
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci相对布局组件,用于复杂场景中元素对齐的布局。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 该组件从API Version 9开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## 规则说明
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci * 容器内子组件区分水平方向,垂直方向:
12e41f4b71Sopenharmony_ci   * 水平方向为left, middle, right,对应容器的HorizontalAlign.StartHorizontalAlign.CenterHorizontalAlign.End13e41f4b71Sopenharmony_ci   * 垂直方向为top, center, bottom,对应容器的VerticalAlign.TopVerticalAlign.CenterVerticalAlign.Bottom14e41f4b71Sopenharmony_ci * 子组件可以将容器、guideline、barrier或者其他子组件设为锚点:
15e41f4b71Sopenharmony_ci   * 参与相对布局的容器内组件,不设置id的组件能显示,但是不能被其他子组件作为锚点,相对布局容器会为其拼接id,此id的规律无法被应用感知;容器id固定为__container__;guideline和barrier的id不能与组件重复,重复的话按照组件 > guideline > barrier的优先级生效。
16e41f4b71Sopenharmony_ci   * 此子组件某一方向上的三个位置(水平方向为left、middle、right,垂直方向为top、center、bottom)可以指定容器或其他子组件同方向的三个位置(水平方向为HorizontalAlign.StartHorizontalAlign.CenterHorizontalAlign.End,垂直方向为VerticalAlign.TopVerticalAlign.CenterVerticalAlign.Bottom)为锚点。若同方向上设置两个以上锚点,水平方向Start和Center优先,垂直方向Top和Center优先。例如,水平方向上指定了left以容器的HorizontalAlign.Start为锚点,middle以容器的HorizontalAlign.Center为锚点,又指定right的锚点为容器的HorizontalAlign.End,当组件的width和容器的width不能同时满足3条约束规则时,优先取Start和Center的约束规则。
17e41f4b71Sopenharmony_ci   * 当同时存在前端页面设置的子组件尺寸和相对布局规则时,子组件的绘制尺寸取决于约束规则。从API Version 11开始,该规则发生变化,子组件绘制尺寸取决于前端页面设置的尺寸。
18e41f4b71Sopenharmony_ci   * 对齐后需要额外偏移可设置offset(API Version 11上新增了[bias](ts-universal-attributes-location.md#bias对象说明), 不建议再使用offset)。
19e41f4b71Sopenharmony_ci   * 从API Version 11开始,在RelativeContainer组件中,width、height设置auto表示自适应子组件。
20e41f4b71Sopenharmony_ci   * 当width设置auto时,如果水平方向上子组件以容器作为锚点,则auto不生效,垂直方向上同理。
21e41f4b71Sopenharmony_ci   * 相对布局容器内的子组件的margin含义不同于通用属性的margin,其含义为到该方向上的锚点的距离。若该方向上没有锚点,则该方向的margin不生效。
22e41f4b71Sopenharmony_ci   * guideline的位置在不声明或者声明异常值(如undefined)时,取start:0的位置;start和end两种方式声明一种即可,同时声明时仅start生效。
23e41f4b71Sopenharmony_ci   * 当容器在某个方向的size声明为“auto”时,该方向上guideline的位置只能使用start的方式声明(不可使用百分比)。
24e41f4b71Sopenharmony_ci   * 垂直方向的guideline和barrier只能作为组件水平方向的锚点,作为垂直方向的锚点时取0;水平方向的guideline和barrier只能作为组件垂直方向的锚点,作为水平方向的锚点时取0。
25e41f4b71Sopenharmony_ci   * 链的形成依靠组件间的依赖关系。以一个组件A、组件B组成的最小水平链为例,需要有锚点1 <-- 组件A <---> 组件B --> 锚点2的依赖关系,即A具有left锚点,B具有right锚点,同时A的right锚点是B的HorizontalAlign.Start,B的left锚点是A的HorizontalAlign.End26e41f4b71Sopenharmony_ci   * 链的方向和格式声明在链头组件的[chainMode](ts-universal-attributes-location.md#chainmode12)接口;链内元素的bias属性全部失效,链头元素的bias作为整个链的bias生效。
27e41f4b71Sopenharmony_ci   * 链内所有元素的size如果超出链的锚点约束,超出的部分将均分在链的两侧。在[Packed](ts-universal-attributes-location.md#chainstyle12)链中,超出部分的分布可以通过[bias](ts-universal-attributes-location.md#bias对象说明)来设置。
28e41f4b71Sopenharmony_ci * 特殊情况
29e41f4b71Sopenharmony_ci   * 根据约束条件和子组件本身的size属性无法确定子组件大小,则子组件不绘制。
30e41f4b71Sopenharmony_ci   * 互相依赖、环形依赖时容器内子组件全部不绘制。
31e41f4b71Sopenharmony_ci   * 同方向上两个及以上位置设置锚点但锚点位置逆序时此子组件大小为0,即不绘制。
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci## 子组件
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci支持多个子组件。
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci## 接口
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ciRelativeContainer()
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci## 属性
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci除支持[通用属性](ts-universal-attributes-size.md)外,还支持如下属性:
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci### guideLine<sup>12+</sup>
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ciguideLine(value: Array&lt;GuideLineStyle&gt;)
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci设置RelativeContainer容器内的辅助线,Array中每个项目即为一条guideline。
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci**参数:** 
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci| 参数名 | 类型                                       | 必填 | 说明                              |
65e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | --------------------------------- |
66e41f4b71Sopenharmony_ci| value  | Array<[GuideLineStyle](#guidelinestyle12对象说明)> | 是   | RelativeContainer容器内的辅助线。 |
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci### barrier<sup>12+</sup>
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_cibarrier(value: Array&lt;BarrierStyle&gt;)
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci设置RelativeContainer容器内的屏障,Array中每个项目即为一条barrier。
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci**参数:** 
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci| 参数名 | 类型                                   | 必填 | 说明                            |
81e41f4b71Sopenharmony_ci| ------ | -------------------------------------- | ---- | ------------------------------- |
82e41f4b71Sopenharmony_ci| value  | Array<[BarrierStyle](#barrierstyle12对象说明)> | 是   | RelativeContainer容器内的屏障。 |
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci### barrier<sup>12+</sup>
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_cibarrier(barrierStyle: Array&lt;LocalizedBarrierStyle&gt;)
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci设置RelativeContaine容器内的屏障,Array中每个项目即为一条barrier。
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci**参数:**
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci| 参数名 | 类型                                   | 必填 | 说明                           |
97e41f4b71Sopenharmony_ci| ------ | -------------------------------------- | ---- | ------------------------------ |
98e41f4b71Sopenharmony_ci| barrierStyle  | Array\<[LocalizedBarrierStyle](#localizedbarrierstyle12对象说明)\> | 是   | RelativeContaine容器内的屏障。 |
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci## GuideLineStyle<sup>12+</sup>对象说明
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ciguideLine参数,用于定义一条guideline的id、方向和位置。
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci| 名称    | 类型      | 必填   | 说明                    |
109e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- |
110e41f4b71Sopenharmony_ci| id  | string  | 是    | guideline的id,必须是唯一的并且不可与容器内组件重名。   |
111e41f4b71Sopenharmony_ci| direction | [Axis](ts-appendix-enums.md#axis) | 是    | 指定guideline的方向。<br />默认值:Axis.Vertical |
112e41f4b71Sopenharmony_ci| position | [GuideLinePosition](#guidelineposition12对象说明) | 是    | 指定guideline的位置。<br />默认值:<br />{<br />start: 0<br />} |
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci## GuideLinePosition<sup>12+</sup>对象说明
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ciguideLine位置参数,用于定义guideline的位置。
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci| 名称    | 类型      | 必填   | 说明                    |
123e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- |
124e41f4b71Sopenharmony_ci| start  | [Dimension](ts-types.md#dimension10)  | 否    | guideline距离容器左侧或者顶部的距离。   |
125e41f4b71Sopenharmony_ci| end | [Dimension](ts-types.md#dimension10) | 否    | guideline距离容器右侧或者底部的距离。 |
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci## BarrierStyle<sup>12+</sup>对象说明
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_cibarrier参数,用于定义一条barrier的id、方向和生成时所依赖的组件。
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci| 名称    | 类型      | 必填   | 说明                    |
136e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- |
137e41f4b71Sopenharmony_ci| id  | string  | 是    | barrier的id,必须是唯一的并且不可与容器内组件重名。   |
138e41f4b71Sopenharmony_ci| direction | [BarrierDirection](ts-container-relativecontainer.md#barrierdirection12) | 是    | 指定barrier的方向。<br />默认值:BarrierDirection.LEFT |
139e41f4b71Sopenharmony_ci| referencedId | Array\<string> | 是    | 指定生成barrier所依赖的组件。 |
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci## BarrierDirection<sup>12+</sup>枚举说明
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci定义屏障线的方向。
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ci| 名称     | 说明                          |
150e41f4b71Sopenharmony_ci| ------ | ----------------------------- |
151e41f4b71Sopenharmony_ci| LEFT | 屏障在其所有[referencedId](ts-container-relativecontainer.md#barrierstyle12对象说明)的最左侧。    |
152e41f4b71Sopenharmony_ci| RIGHT | 屏障在其所有[referencedId](ts-container-relativecontainer.md#barrierstyle12对象说明)的最右侧。   |
153e41f4b71Sopenharmony_ci| TOP  | 屏障在其所有[referencedId](ts-container-relativecontainer.md#barrierstyle12对象说明)的最上方。    |
154e41f4b71Sopenharmony_ci| BOTTOM  | 屏障在其所有[referencedId](ts-container-relativecontainer.md#barrierstyle12对象说明)的最下方。 |
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci## LocalizedBarrierStyle<sup>12+</sup>对象说明
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_cibarrier参数,用于定义一条barrier的id、方向和生成时所依赖的组件。
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ci| 名称    | 类型      | 必填   | 说明              |
165e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- |
166e41f4b71Sopenharmony_ci| id  | string  | 是    | barrier的id,必须是唯一的并且不可与容器内组件重名。   |
167e41f4b71Sopenharmony_ci| localizedDirection | [LocalizedBarrierDirection](#localizedbarrierdirection12枚举说明) | 是    | 指定barrier的方向。 |
168e41f4b71Sopenharmony_ci| referencedId | Array\<string\> | 是    | 指定生成barrier所依赖的组件。 |
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci## LocalizedBarrierDirection<sup>12+</sup>枚举说明
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci定义屏障线的方向。
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci| 名称 |  值  | 说明                       |
179e41f4b71Sopenharmony_ci| ------ | -- | ----------------------------- |
180e41f4b71Sopenharmony_ci| START  | 0  |屏障在其所有[referencedId](#localizedbarrierstyle12对象说明)的最左/右侧,LTR模式时为最左侧,RTL模式时为最右侧。 |
181e41f4b71Sopenharmony_ci| END    | 1  | 屏障在其所有[referencedId](#localizedbarrierstyle12对象说明)的最左/右侧, LTR模式时为最右侧,RTL模式时为最左侧。   |
182e41f4b71Sopenharmony_ci| TOP    | 2  | 屏障在其所有[referencedId](#localizedbarrierstyle12对象说明)的最上方。    |
183e41f4b71Sopenharmony_ci| BOTTOM | 3  | 屏障在其所有[referencedId](#localizedbarrierstyle12对象说明)的最下方。 |
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ci## 示例
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci### 示例1
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci本示例展示了以容器和容器内组件作为锚点进行布局的用法。
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci```ts
192e41f4b71Sopenharmony_ci@Entry
193e41f4b71Sopenharmony_ci@Component
194e41f4b71Sopenharmony_cistruct Index {
195e41f4b71Sopenharmony_ci  build() {
196e41f4b71Sopenharmony_ci    Row() {
197e41f4b71Sopenharmony_ci      RelativeContainer() {
198e41f4b71Sopenharmony_ci        Row(){Text('row1')}.justifyContent(FlexAlign.Center)
199e41f4b71Sopenharmony_ci          .width(100).height(100)
200e41f4b71Sopenharmony_ci          .backgroundColor("#FF3333")
201e41f4b71Sopenharmony_ci          .alignRules({
202e41f4b71Sopenharmony_ci            top: {anchor: "__container__", align: VerticalAlign.Top},
203e41f4b71Sopenharmony_ci            left: {anchor: "__container__", align: HorizontalAlign.Start}
204e41f4b71Sopenharmony_ci          })
205e41f4b71Sopenharmony_ci          .id("row1")
206e41f4b71Sopenharmony_ci
207e41f4b71Sopenharmony_ci        Row(){Text('row2')}.justifyContent(FlexAlign.Center)
208e41f4b71Sopenharmony_ci          .width(100).height(100)
209e41f4b71Sopenharmony_ci          .backgroundColor("#FFCC00")
210e41f4b71Sopenharmony_ci          .alignRules({
211e41f4b71Sopenharmony_ci            top: {anchor: "__container__", align: VerticalAlign.Top},
212e41f4b71Sopenharmony_ci            right: {anchor: "__container__", align: HorizontalAlign.End}
213e41f4b71Sopenharmony_ci          })
214e41f4b71Sopenharmony_ci          .id("row2")
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_ci        Row(){Text('row3')}.justifyContent(FlexAlign.Center)
217e41f4b71Sopenharmony_ci          .height(100)
218e41f4b71Sopenharmony_ci          .backgroundColor("#FF6633")
219e41f4b71Sopenharmony_ci          .alignRules({
220e41f4b71Sopenharmony_ci            top: {anchor: "row1", align: VerticalAlign.Bottom},
221e41f4b71Sopenharmony_ci            left: {anchor: "row1", align: HorizontalAlign.End},
222e41f4b71Sopenharmony_ci            right: {anchor: "row2", align: HorizontalAlign.Start}
223e41f4b71Sopenharmony_ci          })
224e41f4b71Sopenharmony_ci          .id("row3")
225e41f4b71Sopenharmony_ci
226e41f4b71Sopenharmony_ci        Row(){Text('row4')}.justifyContent(FlexAlign.Center)
227e41f4b71Sopenharmony_ci          .backgroundColor("#FF9966")
228e41f4b71Sopenharmony_ci          .alignRules({
229e41f4b71Sopenharmony_ci            top: {anchor: "row3", align: VerticalAlign.Bottom},
230e41f4b71Sopenharmony_ci            bottom: {anchor: "__container__", align: VerticalAlign.Bottom},
231e41f4b71Sopenharmony_ci            left: {anchor: "__container__", align: HorizontalAlign.Start},
232e41f4b71Sopenharmony_ci            right: {anchor: "row1", align: HorizontalAlign.End}
233e41f4b71Sopenharmony_ci          })
234e41f4b71Sopenharmony_ci          .id("row4")
235e41f4b71Sopenharmony_ci
236e41f4b71Sopenharmony_ci        Row(){Text('row5')}.justifyContent(FlexAlign.Center)
237e41f4b71Sopenharmony_ci          .backgroundColor("#FF66FF")
238e41f4b71Sopenharmony_ci          .alignRules({
239e41f4b71Sopenharmony_ci            top: {anchor: "row3", align: VerticalAlign.Bottom},
240e41f4b71Sopenharmony_ci            bottom: {anchor: "__container__", align: VerticalAlign.Bottom},
241e41f4b71Sopenharmony_ci            left: {anchor: "row2", align: HorizontalAlign.Start},
242e41f4b71Sopenharmony_ci            right: {anchor: "__container__", align: HorizontalAlign.End}
243e41f4b71Sopenharmony_ci          })
244e41f4b71Sopenharmony_ci          .id("row5")
245e41f4b71Sopenharmony_ci      }
246e41f4b71Sopenharmony_ci      .width(300).height(300)
247e41f4b71Sopenharmony_ci      .margin({left: 50})
248e41f4b71Sopenharmony_ci      .border({width:2, color: "#6699FF"})
249e41f4b71Sopenharmony_ci    }
250e41f4b71Sopenharmony_ci    .height('100%')
251e41f4b71Sopenharmony_ci  }
252e41f4b71Sopenharmony_ci}
253e41f4b71Sopenharmony_ci```
254e41f4b71Sopenharmony_ci![relative container](figures/relativecontainer.png)
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ci### 示例2
257e41f4b71Sopenharmony_ci
258e41f4b71Sopenharmony_ci本示例展示了容器内子组件设置margin的用法。
259e41f4b71Sopenharmony_ci
260e41f4b71Sopenharmony_ci```ts
261e41f4b71Sopenharmony_ci@Entry
262e41f4b71Sopenharmony_ci@Component
263e41f4b71Sopenharmony_cistruct Index {
264e41f4b71Sopenharmony_ci  build() {
265e41f4b71Sopenharmony_ci    Row() {
266e41f4b71Sopenharmony_ci      RelativeContainer() {
267e41f4b71Sopenharmony_ci        Row(){Text('row1')}.justifyContent(FlexAlign.Center)
268e41f4b71Sopenharmony_ci          .width(100).height(100)
269e41f4b71Sopenharmony_ci          .backgroundColor("#FF3333")
270e41f4b71Sopenharmony_ci          .alignRules({
271e41f4b71Sopenharmony_ci            top: {anchor: "__container__", align: VerticalAlign.Top},
272e41f4b71Sopenharmony_ci            left: {anchor: "__container__", align: HorizontalAlign.Start}
273e41f4b71Sopenharmony_ci          })
274e41f4b71Sopenharmony_ci          .id("row1")
275e41f4b71Sopenharmony_ci          .margin(10)
276e41f4b71Sopenharmony_ci
277e41f4b71Sopenharmony_ci        Row(){Text('row2')}.justifyContent(FlexAlign.Center)
278e41f4b71Sopenharmony_ci          .width(100).height(100)
279e41f4b71Sopenharmony_ci          .backgroundColor("#FFCC00")
280e41f4b71Sopenharmony_ci          .alignRules({
281e41f4b71Sopenharmony_ci            left: {anchor: "row1", align: HorizontalAlign.End},
282e41f4b71Sopenharmony_ci            top: {anchor: "row1", align: VerticalAlign.Top}
283e41f4b71Sopenharmony_ci          })
284e41f4b71Sopenharmony_ci          .id("row2")
285e41f4b71Sopenharmony_ci
286e41f4b71Sopenharmony_ci        Row(){Text('row3')}.justifyContent(FlexAlign.Center)
287e41f4b71Sopenharmony_ci          .width(100).height(100)
288e41f4b71Sopenharmony_ci          .backgroundColor("#FF6633")
289e41f4b71Sopenharmony_ci          .alignRules({
290e41f4b71Sopenharmony_ci            left: {anchor: "row1", align: HorizontalAlign.Start},
291e41f4b71Sopenharmony_ci            top: {anchor: "row1", align: VerticalAlign.Bottom}
292e41f4b71Sopenharmony_ci          })
293e41f4b71Sopenharmony_ci          .id("row3")
294e41f4b71Sopenharmony_ci
295e41f4b71Sopenharmony_ci        Row(){Text('row4')}.justifyContent(FlexAlign.Center)
296e41f4b71Sopenharmony_ci          .width(100).height(100)
297e41f4b71Sopenharmony_ci          .backgroundColor("#FF9966")
298e41f4b71Sopenharmony_ci          .alignRules({
299e41f4b71Sopenharmony_ci            left: {anchor: "row3", align: HorizontalAlign.End},
300e41f4b71Sopenharmony_ci            top: {anchor: "row2", align: VerticalAlign.Bottom}
301e41f4b71Sopenharmony_ci          })
302e41f4b71Sopenharmony_ci          .id("row4")
303e41f4b71Sopenharmony_ci          .margin(10)
304e41f4b71Sopenharmony_ci      }
305e41f4b71Sopenharmony_ci      .width(300).height(300)
306e41f4b71Sopenharmony_ci      .margin({left: 50})
307e41f4b71Sopenharmony_ci      .border({width:2, color: "#6699FF"})
308e41f4b71Sopenharmony_ci    }
309e41f4b71Sopenharmony_ci    .height('100%')
310e41f4b71Sopenharmony_ci  }
311e41f4b71Sopenharmony_ci}
312e41f4b71Sopenharmony_ci```
313e41f4b71Sopenharmony_ci![relative container](figures/relativecontainer1.png)
314e41f4b71Sopenharmony_ci
315e41f4b71Sopenharmony_ci### 示例3
316e41f4b71Sopenharmony_ci
317e41f4b71Sopenharmony_ci本示例展示了容器大小适应内容(声明size为"auto")的用法。
318e41f4b71Sopenharmony_ci
319e41f4b71Sopenharmony_ci```ts
320e41f4b71Sopenharmony_ci@Entry
321e41f4b71Sopenharmony_ci@Component
322e41f4b71Sopenharmony_cistruct Index {
323e41f4b71Sopenharmony_ci  build() {
324e41f4b71Sopenharmony_ci    Row() {
325e41f4b71Sopenharmony_ci      RelativeContainer() {
326e41f4b71Sopenharmony_ci        Row(){Text('row1')}.justifyContent(FlexAlign.Center)
327e41f4b71Sopenharmony_ci          .width(100).height(100)
328e41f4b71Sopenharmony_ci          .backgroundColor("#FF3333")
329e41f4b71Sopenharmony_ci          .id("row1")
330e41f4b71Sopenharmony_ci
331e41f4b71Sopenharmony_ci        Row(){Text('row2')}.justifyContent(FlexAlign.Center)
332e41f4b71Sopenharmony_ci          .width(100).height(100)
333e41f4b71Sopenharmony_ci          .backgroundColor("#FFCC00")
334e41f4b71Sopenharmony_ci          .alignRules({
335e41f4b71Sopenharmony_ci            left: {anchor: "row1", align: HorizontalAlign.End},
336e41f4b71Sopenharmony_ci            top: {anchor: "row1", align: VerticalAlign.Top}
337e41f4b71Sopenharmony_ci          })
338e41f4b71Sopenharmony_ci          .id("row2")
339e41f4b71Sopenharmony_ci
340e41f4b71Sopenharmony_ci        Row(){Text('row3')}.justifyContent(FlexAlign.Center)
341e41f4b71Sopenharmony_ci          .width(100).height(100)
342e41f4b71Sopenharmony_ci          .backgroundColor("#FF6633")
343e41f4b71Sopenharmony_ci          .alignRules({
344e41f4b71Sopenharmony_ci            left: {anchor: "row1", align: HorizontalAlign.Start},
345e41f4b71Sopenharmony_ci            top: {anchor: "row1", align: VerticalAlign.Bottom}
346e41f4b71Sopenharmony_ci          })
347e41f4b71Sopenharmony_ci          .id("row3")
348e41f4b71Sopenharmony_ci
349e41f4b71Sopenharmony_ci        Row(){Text('row4')}.justifyContent(FlexAlign.Center)
350e41f4b71Sopenharmony_ci          .width(100).height(100)
351e41f4b71Sopenharmony_ci          .backgroundColor("#FF9966")
352e41f4b71Sopenharmony_ci          .alignRules({
353e41f4b71Sopenharmony_ci            left: {anchor: "row3", align: HorizontalAlign.End},
354e41f4b71Sopenharmony_ci            top: {anchor: "row2", align: VerticalAlign.Bottom}
355e41f4b71Sopenharmony_ci          })
356e41f4b71Sopenharmony_ci          .id("row4")
357e41f4b71Sopenharmony_ci      }
358e41f4b71Sopenharmony_ci      .width("auto").height("auto")
359e41f4b71Sopenharmony_ci      .margin({left: 50})
360e41f4b71Sopenharmony_ci      .border({width:2, color: "#6699FF"})
361e41f4b71Sopenharmony_ci    }
362e41f4b71Sopenharmony_ci    .height('100%')
363e41f4b71Sopenharmony_ci  }
364e41f4b71Sopenharmony_ci}
365e41f4b71Sopenharmony_ci```
366e41f4b71Sopenharmony_ci![relative container](figures/relativecontainer2.png)
367e41f4b71Sopenharmony_ci
368e41f4b71Sopenharmony_ci### 示例4
369e41f4b71Sopenharmony_ci
370e41f4b71Sopenharmony_ci本示例展示了bias的用法。
371e41f4b71Sopenharmony_ci
372e41f4b71Sopenharmony_ci```ts
373e41f4b71Sopenharmony_ci@Entry
374e41f4b71Sopenharmony_ci@Component
375e41f4b71Sopenharmony_cistruct Index {
376e41f4b71Sopenharmony_ci  build() {
377e41f4b71Sopenharmony_ci    Row() {
378e41f4b71Sopenharmony_ci      RelativeContainer() {
379e41f4b71Sopenharmony_ci        Row().width(100).height(100)
380e41f4b71Sopenharmony_ci          .backgroundColor("#FF3333")
381e41f4b71Sopenharmony_ci          .alignRules({
382e41f4b71Sopenharmony_ci            top: {anchor: "__container__", align: VerticalAlign.Top},
383e41f4b71Sopenharmony_ci            bottom : {anchor : "__container__", align : VerticalAlign.Bottom},
384e41f4b71Sopenharmony_ci            left: {anchor: "__container__", align: HorizontalAlign.Start},
385e41f4b71Sopenharmony_ci            right : {anchor : "__container__", align: HorizontalAlign.End},
386e41f4b71Sopenharmony_ci            bias : {vertical : 0.3}
387e41f4b71Sopenharmony_ci          })
388e41f4b71Sopenharmony_ci          .id("row1")
389e41f4b71Sopenharmony_ci      }
390e41f4b71Sopenharmony_ci      .width(300).height(300)
391e41f4b71Sopenharmony_ci      .margin({left: 50})
392e41f4b71Sopenharmony_ci      .border({width:2, color: "#6699FF"})
393e41f4b71Sopenharmony_ci    }
394e41f4b71Sopenharmony_ci    .height('100%')
395e41f4b71Sopenharmony_ci  }
396e41f4b71Sopenharmony_ci}
397e41f4b71Sopenharmony_ci```
398e41f4b71Sopenharmony_ci![relative container](figures/relativecontainer3.png)
399e41f4b71Sopenharmony_ci
400e41f4b71Sopenharmony_ci### 示例5
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_ci本示例展示了guideline的声明和以guideline为锚点的用法。
403e41f4b71Sopenharmony_ci
404e41f4b71Sopenharmony_ci```ts
405e41f4b71Sopenharmony_ci@Entry
406e41f4b71Sopenharmony_ci@Component
407e41f4b71Sopenharmony_cistruct Index {
408e41f4b71Sopenharmony_ci  build() {
409e41f4b71Sopenharmony_ci    Row() {
410e41f4b71Sopenharmony_ci      RelativeContainer() {
411e41f4b71Sopenharmony_ci        Row().width(100).height(100)
412e41f4b71Sopenharmony_ci          .backgroundColor("#FF3333")
413e41f4b71Sopenharmony_ci          .alignRules({
414e41f4b71Sopenharmony_ci            left: {anchor: "guideline1", align: HorizontalAlign.End},
415e41f4b71Sopenharmony_ci            top: {anchor: "guideline2", align: VerticalAlign.Top}
416e41f4b71Sopenharmony_ci          })
417e41f4b71Sopenharmony_ci          .id("row1")
418e41f4b71Sopenharmony_ci      }
419e41f4b71Sopenharmony_ci      .width(300).height(300)
420e41f4b71Sopenharmony_ci      .margin({left: 50})
421e41f4b71Sopenharmony_ci      .border({width:2, color: "#6699FF"})
422e41f4b71Sopenharmony_ci      .guideLine([{id:"guideline1", direction: Axis.Vertical, position:{start:50}},
423e41f4b71Sopenharmony_ci        {id:"guideline2", direction: Axis.Horizontal, position:{start:50}}])
424e41f4b71Sopenharmony_ci    }
425e41f4b71Sopenharmony_ci    .height('100%')
426e41f4b71Sopenharmony_ci  }
427e41f4b71Sopenharmony_ci}
428e41f4b71Sopenharmony_ci```
429e41f4b71Sopenharmony_ci![relative container](figures/relativecontainer4.png)
430e41f4b71Sopenharmony_ci
431e41f4b71Sopenharmony_ci### 示例6
432e41f4b71Sopenharmony_ci
433e41f4b71Sopenharmony_ci本示例展示了barrier的声明和以barrier为锚点的用法。
434e41f4b71Sopenharmony_ci
435e41f4b71Sopenharmony_ci```ts
436e41f4b71Sopenharmony_ci@Entry
437e41f4b71Sopenharmony_ci@Component
438e41f4b71Sopenharmony_cistruct Index {
439e41f4b71Sopenharmony_ci  build() {
440e41f4b71Sopenharmony_ci    Row() {
441e41f4b71Sopenharmony_ci      RelativeContainer() {
442e41f4b71Sopenharmony_ci        Row(){Text('row1')}.justifyContent(FlexAlign.Center)
443e41f4b71Sopenharmony_ci          .width(100).height(100)
444e41f4b71Sopenharmony_ci          .backgroundColor("#FF3333")
445e41f4b71Sopenharmony_ci          .id("row1")
446e41f4b71Sopenharmony_ci
447e41f4b71Sopenharmony_ci        Row(){Text('row2')}.justifyContent(FlexAlign.Center)
448e41f4b71Sopenharmony_ci          .width(100).height(100)
449e41f4b71Sopenharmony_ci          .backgroundColor("#FFCC00")
450e41f4b71Sopenharmony_ci          .alignRules({
451e41f4b71Sopenharmony_ci            middle: {anchor: "row1", align: HorizontalAlign.End},
452e41f4b71Sopenharmony_ci            top: {anchor: "row1", align: VerticalAlign.Bottom}
453e41f4b71Sopenharmony_ci          })
454e41f4b71Sopenharmony_ci          .id("row2")
455e41f4b71Sopenharmony_ci
456e41f4b71Sopenharmony_ci        Row(){Text('row3')}.justifyContent(FlexAlign.Center)
457e41f4b71Sopenharmony_ci          .width(100).height(100)
458e41f4b71Sopenharmony_ci          .backgroundColor("#FF6633")
459e41f4b71Sopenharmony_ci          .alignRules({
460e41f4b71Sopenharmony_ci            left: {anchor: "barrier1", align: HorizontalAlign.End},
461e41f4b71Sopenharmony_ci            top: {anchor: "row1", align: VerticalAlign.Top}
462e41f4b71Sopenharmony_ci          })
463e41f4b71Sopenharmony_ci          .id("row3")
464e41f4b71Sopenharmony_ci
465e41f4b71Sopenharmony_ci        Row(){Text('row4')}.justifyContent(FlexAlign.Center)
466e41f4b71Sopenharmony_ci          .width(50).height(50)
467e41f4b71Sopenharmony_ci          .backgroundColor("#FF9966")
468e41f4b71Sopenharmony_ci          .alignRules({
469e41f4b71Sopenharmony_ci            left: {anchor: "row1", align: HorizontalAlign.Start},
470e41f4b71Sopenharmony_ci            top: {anchor: "barrier2", align: VerticalAlign.Bottom}
471e41f4b71Sopenharmony_ci          })
472e41f4b71Sopenharmony_ci          .id("row4")
473e41f4b71Sopenharmony_ci      }
474e41f4b71Sopenharmony_ci      .width(300).height(300)
475e41f4b71Sopenharmony_ci      .margin({left: 50})
476e41f4b71Sopenharmony_ci      .border({width:2, color: "#6699FF"})
477e41f4b71Sopenharmony_ci      .barrier([{id: "barrier1", direction: BarrierDirection.RIGHT, referencedId:["row1", "row2"]},
478e41f4b71Sopenharmony_ci        {id: "barrier2", direction: BarrierDirection.BOTTOM, referencedId:["row1", "row2"]}])
479e41f4b71Sopenharmony_ci    }
480e41f4b71Sopenharmony_ci    .height('100%')
481e41f4b71Sopenharmony_ci  }
482e41f4b71Sopenharmony_ci}
483e41f4b71Sopenharmony_ci```
484e41f4b71Sopenharmony_ci![relative container](figures/relativecontainer5.png)
485e41f4b71Sopenharmony_ci
486e41f4b71Sopenharmony_ci### 示例7
487e41f4b71Sopenharmony_ci
488e41f4b71Sopenharmony_ci本示例通过chainMode接口从上至下分别实现了水平方向的SPREAD链,SPREAD_INSIDE链和PACKED链。
489e41f4b71Sopenharmony_ci
490e41f4b71Sopenharmony_ci```ts
491e41f4b71Sopenharmony_ci@Entry
492e41f4b71Sopenharmony_ci@Component
493e41f4b71Sopenharmony_cistruct Index {
494e41f4b71Sopenharmony_ci  build() {
495e41f4b71Sopenharmony_ci    Row() {
496e41f4b71Sopenharmony_ci      RelativeContainer() {
497e41f4b71Sopenharmony_ci        Row(){Text('row1')}.justifyContent(FlexAlign.Center)
498e41f4b71Sopenharmony_ci          .width(80).height(80)
499e41f4b71Sopenharmony_ci          .backgroundColor("#FF3333")
500e41f4b71Sopenharmony_ci          .alignRules({
501e41f4b71Sopenharmony_ci            left: {anchor: "__container__", align: HorizontalAlign.Start},
502e41f4b71Sopenharmony_ci            right: {anchor: "row2", align : HorizontalAlign.Start},
503e41f4b71Sopenharmony_ci            top: {anchor: "__container__", align: VerticalAlign.Top}
504e41f4b71Sopenharmony_ci          })
505e41f4b71Sopenharmony_ci          .id("row1")
506e41f4b71Sopenharmony_ci          .chainMode(Axis.Horizontal, ChainStyle.SPREAD)
507e41f4b71Sopenharmony_ci
508e41f4b71Sopenharmony_ci        Row(){Text('row2')}.justifyContent(FlexAlign.Center)
509e41f4b71Sopenharmony_ci          .width(80).height(80)
510e41f4b71Sopenharmony_ci          .backgroundColor("#FFCC00")
511e41f4b71Sopenharmony_ci          .alignRules({
512e41f4b71Sopenharmony_ci            left: {anchor: "row1", align: HorizontalAlign.End},
513e41f4b71Sopenharmony_ci            right: {anchor: "row3", align : HorizontalAlign.Start},
514e41f4b71Sopenharmony_ci            top: {anchor: "row1", align: VerticalAlign.Top}
515e41f4b71Sopenharmony_ci          })
516e41f4b71Sopenharmony_ci          .id("row2")
517e41f4b71Sopenharmony_ci
518e41f4b71Sopenharmony_ci        Row(){Text('row3')}.justifyContent(FlexAlign.Center)
519e41f4b71Sopenharmony_ci          .width(80).height(80)
520e41f4b71Sopenharmony_ci          .backgroundColor("#FF6633")
521e41f4b71Sopenharmony_ci          .alignRules({
522e41f4b71Sopenharmony_ci            left: {anchor: "row2", align: HorizontalAlign.End},
523e41f4b71Sopenharmony_ci            right: {anchor: "__container__", align : HorizontalAlign.End},
524e41f4b71Sopenharmony_ci            top: {anchor: "row1", align: VerticalAlign.Top}
525e41f4b71Sopenharmony_ci          })
526e41f4b71Sopenharmony_ci          .id("row3")
527e41f4b71Sopenharmony_ci
528e41f4b71Sopenharmony_ci        Row(){Text('row4')}.justifyContent(FlexAlign.Center)
529e41f4b71Sopenharmony_ci          .width(80).height(80)
530e41f4b71Sopenharmony_ci          .backgroundColor("#FF3333")
531e41f4b71Sopenharmony_ci          .alignRules({
532e41f4b71Sopenharmony_ci            left: {anchor: "__container__", align: HorizontalAlign.Start},
533e41f4b71Sopenharmony_ci            right: {anchor: "row5", align : HorizontalAlign.Start},
534e41f4b71Sopenharmony_ci            center: {anchor: "__container__", align: VerticalAlign.Center}
535e41f4b71Sopenharmony_ci          })
536e41f4b71Sopenharmony_ci          .id("row4")
537e41f4b71Sopenharmony_ci          .chainMode(Axis.Horizontal, ChainStyle.SPREAD_INSIDE)
538e41f4b71Sopenharmony_ci
539e41f4b71Sopenharmony_ci        Row(){Text('row5')}.justifyContent(FlexAlign.Center)
540e41f4b71Sopenharmony_ci          .width(80).height(80)
541e41f4b71Sopenharmony_ci          .backgroundColor("#FFCC00")
542e41f4b71Sopenharmony_ci          .alignRules({
543e41f4b71Sopenharmony_ci            left: {anchor: "row4", align: HorizontalAlign.End},
544e41f4b71Sopenharmony_ci            right: {anchor: "row6", align : HorizontalAlign.Start},
545e41f4b71Sopenharmony_ci            top: {anchor: "row4", align: VerticalAlign.Top}
546e41f4b71Sopenharmony_ci          })
547e41f4b71Sopenharmony_ci          .id("row5")
548e41f4b71Sopenharmony_ci
549e41f4b71Sopenharmony_ci        Row(){Text('row6')}.justifyContent(FlexAlign.Center)
550e41f4b71Sopenharmony_ci          .width(80).height(80)
551e41f4b71Sopenharmony_ci          .backgroundColor("#FF6633")
552e41f4b71Sopenharmony_ci          .alignRules({
553e41f4b71Sopenharmony_ci            left: {anchor: "row5", align: HorizontalAlign.End},
554e41f4b71Sopenharmony_ci            right: {anchor: "__container__", align : HorizontalAlign.End},
555e41f4b71Sopenharmony_ci            top: {anchor: "row4", align: VerticalAlign.Top}
556e41f4b71Sopenharmony_ci          })
557e41f4b71Sopenharmony_ci          .id("row6")
558e41f4b71Sopenharmony_ci
559e41f4b71Sopenharmony_ci        Row(){Text('row7')}.justifyContent(FlexAlign.Center)
560e41f4b71Sopenharmony_ci          .width(80).height(80)
561e41f4b71Sopenharmony_ci          .backgroundColor("#FF3333")
562e41f4b71Sopenharmony_ci          .alignRules({
563e41f4b71Sopenharmony_ci            left: {anchor: "__container__", align: HorizontalAlign.Start},
564e41f4b71Sopenharmony_ci            right: {anchor: "row8", align : HorizontalAlign.Start},
565e41f4b71Sopenharmony_ci            bottom: {anchor: "__container__", align: VerticalAlign.Bottom}
566e41f4b71Sopenharmony_ci          })
567e41f4b71Sopenharmony_ci          .id("row7")
568e41f4b71Sopenharmony_ci          .chainMode(Axis.Horizontal, ChainStyle.PACKED)
569e41f4b71Sopenharmony_ci
570e41f4b71Sopenharmony_ci        Row(){Text('row8')}.justifyContent(FlexAlign.Center)
571e41f4b71Sopenharmony_ci          .width(80).height(80)
572e41f4b71Sopenharmony_ci          .backgroundColor("#FFCC00")
573e41f4b71Sopenharmony_ci          .alignRules({
574e41f4b71Sopenharmony_ci            left: {anchor: "row7", align: HorizontalAlign.End},
575e41f4b71Sopenharmony_ci            right: {anchor: "row9", align : HorizontalAlign.Start},
576e41f4b71Sopenharmony_ci            top: {anchor: "row7", align: VerticalAlign.Top}
577e41f4b71Sopenharmony_ci          })
578e41f4b71Sopenharmony_ci          .id("row8")
579e41f4b71Sopenharmony_ci
580e41f4b71Sopenharmony_ci        Row(){Text('row9')}.justifyContent(FlexAlign.Center)
581e41f4b71Sopenharmony_ci          .width(80).height(80)
582e41f4b71Sopenharmony_ci          .backgroundColor("#FF6633")
583e41f4b71Sopenharmony_ci          .alignRules({
584e41f4b71Sopenharmony_ci            left: {anchor: "row8", align: HorizontalAlign.End},
585e41f4b71Sopenharmony_ci            right: {anchor: "__container__", align : HorizontalAlign.End},
586e41f4b71Sopenharmony_ci            top: {anchor: "row7", align: VerticalAlign.Top}
587e41f4b71Sopenharmony_ci          })
588e41f4b71Sopenharmony_ci          .id("row9")
589e41f4b71Sopenharmony_ci      }
590e41f4b71Sopenharmony_ci      .width(300).height(300)
591e41f4b71Sopenharmony_ci      .margin({left: 50})
592e41f4b71Sopenharmony_ci      .border({width:2, color: "#6699FF"})
593e41f4b71Sopenharmony_ci    }
594e41f4b71Sopenharmony_ci    .height('100%')
595e41f4b71Sopenharmony_ci  }
596e41f4b71Sopenharmony_ci}
597e41f4b71Sopenharmony_ci```
598e41f4b71Sopenharmony_ci![relative container](figures/relativecontainer6.png)
599e41f4b71Sopenharmony_ci
600e41f4b71Sopenharmony_ci### 示例8
601e41f4b71Sopenharmony_ci
602e41f4b71Sopenharmony_ci本示例通过chainMode和bias接口实现了水平方向的带bias的PACKED链。
603e41f4b71Sopenharmony_ci
604e41f4b71Sopenharmony_ci```ts
605e41f4b71Sopenharmony_ci@Entry
606e41f4b71Sopenharmony_ci@Component
607e41f4b71Sopenharmony_cistruct Index {
608e41f4b71Sopenharmony_ci  build() {
609e41f4b71Sopenharmony_ci    Row() {
610e41f4b71Sopenharmony_ci      RelativeContainer() {
611e41f4b71Sopenharmony_ci        Row(){Text('row1')}.justifyContent(FlexAlign.Center)
612e41f4b71Sopenharmony_ci          .width(80).height(80)
613e41f4b71Sopenharmony_ci          .backgroundColor("#FF3333")
614e41f4b71Sopenharmony_ci          .alignRules({
615e41f4b71Sopenharmony_ci            left: {anchor: "__container__", align: HorizontalAlign.Start},
616e41f4b71Sopenharmony_ci            right: {anchor: "row2", align : HorizontalAlign.Start},
617e41f4b71Sopenharmony_ci            center: {anchor: "__container__", align: VerticalAlign.Center},
618e41f4b71Sopenharmony_ci            bias : {horizontal : 0}
619e41f4b71Sopenharmony_ci          })
620e41f4b71Sopenharmony_ci          .id("row1")
621e41f4b71Sopenharmony_ci          .chainMode(Axis.Horizontal, ChainStyle.PACKED)
622e41f4b71Sopenharmony_ci
623e41f4b71Sopenharmony_ci        Row(){Text('row2')}.justifyContent(FlexAlign.Center)
624e41f4b71Sopenharmony_ci          .width(80).height(80)
625e41f4b71Sopenharmony_ci          .backgroundColor("#FFCC00")
626e41f4b71Sopenharmony_ci          .alignRules({
627e41f4b71Sopenharmony_ci            left: {anchor: "row1", align: HorizontalAlign.End},
628e41f4b71Sopenharmony_ci            right: {anchor: "row3", align : HorizontalAlign.Start},
629e41f4b71Sopenharmony_ci            top: {anchor: "row1", align: VerticalAlign.Top}
630e41f4b71Sopenharmony_ci          })
631e41f4b71Sopenharmony_ci          .id("row2")
632e41f4b71Sopenharmony_ci
633e41f4b71Sopenharmony_ci        Row(){Text('row3')}.justifyContent(FlexAlign.Center)
634e41f4b71Sopenharmony_ci          .width(80).height(80)
635e41f4b71Sopenharmony_ci          .backgroundColor("#FF6633")
636e41f4b71Sopenharmony_ci          .alignRules({
637e41f4b71Sopenharmony_ci            left: {anchor: "row2", align: HorizontalAlign.End},
638e41f4b71Sopenharmony_ci            right: {anchor: "__container__", align : HorizontalAlign.End},
639e41f4b71Sopenharmony_ci            top: {anchor: "row1", align: VerticalAlign.Top}
640e41f4b71Sopenharmony_ci          })
641e41f4b71Sopenharmony_ci          .id("row3")
642e41f4b71Sopenharmony_ci      }
643e41f4b71Sopenharmony_ci      .width(300).height(300)
644e41f4b71Sopenharmony_ci      .margin({left: 50})
645e41f4b71Sopenharmony_ci      .border({width:2, color: "#6699FF"})
646e41f4b71Sopenharmony_ci    }
647e41f4b71Sopenharmony_ci    .height('100%')
648e41f4b71Sopenharmony_ci  }
649e41f4b71Sopenharmony_ci}
650e41f4b71Sopenharmony_ci```
651e41f4b71Sopenharmony_ci![relative container](figures/relativecontainer7.png)
652e41f4b71Sopenharmony_ci
653e41f4b71Sopenharmony_ci### 示例9
654e41f4b71Sopenharmony_ci
655e41f4b71Sopenharmony_ci本示例展示了在RTL模式下以barrier为锚点时使用LocalizedAlignRuleOptions和LocalizedBarrierDirection设置对齐方式的用法。
656e41f4b71Sopenharmony_ci
657e41f4b71Sopenharmony_ci```ts
658e41f4b71Sopenharmony_ci@Entry
659e41f4b71Sopenharmony_ci@Component
660e41f4b71Sopenharmony_cistruct Index {
661e41f4b71Sopenharmony_ci  build() {
662e41f4b71Sopenharmony_ci    Row() {
663e41f4b71Sopenharmony_ci      RelativeContainer() {
664e41f4b71Sopenharmony_ci        Row(){Text('row1')}.justifyContent(FlexAlign.Center)
665e41f4b71Sopenharmony_ci          .width(100).height(100)
666e41f4b71Sopenharmony_ci          .backgroundColor("#FF3333")
667e41f4b71Sopenharmony_ci          .id("row1")
668e41f4b71Sopenharmony_ci
669e41f4b71Sopenharmony_ci        Row(){Text('row2')}.justifyContent(FlexAlign.Center)
670e41f4b71Sopenharmony_ci          .width(100).height(100)
671e41f4b71Sopenharmony_ci          .backgroundColor("#FFCC00")
672e41f4b71Sopenharmony_ci          .alignRules({
673e41f4b71Sopenharmony_ci            middle: {anchor: "row1", align: HorizontalAlign.End},
674e41f4b71Sopenharmony_ci            top: {anchor: "row1", align: VerticalAlign.Bottom}
675e41f4b71Sopenharmony_ci          })
676e41f4b71Sopenharmony_ci          .id("row2")
677e41f4b71Sopenharmony_ci
678e41f4b71Sopenharmony_ci        Row(){Text('row3')}.justifyContent(FlexAlign.Center)
679e41f4b71Sopenharmony_ci          .width(100).height(100)
680e41f4b71Sopenharmony_ci          .backgroundColor("#FF6633")
681e41f4b71Sopenharmony_ci          .alignRules({
682e41f4b71Sopenharmony_ci            start: {anchor: "barrier1", align: HorizontalAlign.End},
683e41f4b71Sopenharmony_ci            top: {anchor: "row1", align: VerticalAlign.Top}
684e41f4b71Sopenharmony_ci          })
685e41f4b71Sopenharmony_ci          .id("row3")
686e41f4b71Sopenharmony_ci
687e41f4b71Sopenharmony_ci        Row(){Text('row4')}.justifyContent(FlexAlign.Center)
688e41f4b71Sopenharmony_ci          .width(50).height(50)
689e41f4b71Sopenharmony_ci          .backgroundColor("#FF9966")
690e41f4b71Sopenharmony_ci          .alignRules({
691e41f4b71Sopenharmony_ci            start: {anchor: "row1", align: HorizontalAlign.Start},
692e41f4b71Sopenharmony_ci            top: {anchor: "barrier2", align: VerticalAlign.Bottom}
693e41f4b71Sopenharmony_ci          })
694e41f4b71Sopenharmony_ci          .id("row4")
695e41f4b71Sopenharmony_ci      }
696e41f4b71Sopenharmony_ci      .direction(Direction.Rtl)
697e41f4b71Sopenharmony_ci      .width(300).height(300)
698e41f4b71Sopenharmony_ci      .margin({left: 50})
699e41f4b71Sopenharmony_ci      .border({width:2, color: "#6699FF"})
700e41f4b71Sopenharmony_ci      .barrier([{id: "barrier1", localizedDirection: LocalizedBarrierDirection.END, referencedId:["row1", "row2"]},
701e41f4b71Sopenharmony_ci        {id: "barrier2", localizedDirection: LocalizedBarrierDirection.BOTTOM, referencedId:["row1", "row2"]}])
702e41f4b71Sopenharmony_ci    }
703e41f4b71Sopenharmony_ci    .height('100%')
704e41f4b71Sopenharmony_ci  }
705e41f4b71Sopenharmony_ci}
706e41f4b71Sopenharmony_ci```
707e41f4b71Sopenharmony_ci![relative container](figures/relativecontainer8.png)