1e41f4b71Sopenharmony_ci# Location
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe location attributes set the alignment mode, layout direction, and position of a component.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci>  The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## align
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_cialign(value: Alignment)
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ciSets the alignment mode of the component content in the drawing area.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**Parameters**
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci| Name| Type                                       | Mandatory| Description                                                        |
24e41f4b71Sopenharmony_ci| ------ | ------------------------------------------- | ---- | ------------------------------------------------------------ |
25e41f4b71Sopenharmony_ci| value  | [Alignment](ts-appendix-enums.md#alignment) | Yes  | Sets the alignment mode of the component content in the drawing area.<br>This attribute is available only in the following components: **\<Stack>**, **\<Button>**, **\<StepperItem>**,**\<FolderStack>**, **\<Marquee>**, **\<Text>**, **\<TextArea>**, and **\<TextInput>**. For details about the alignment results of text-related components (the last four aforementioned components), see [textAlign](ts-basic-components-text.md#attributes).<br>If the component does not support the **textAlign** attribute, horizontal alignment cannot be set for text.<br>Default value: **Alignment.Center**<br>**NOTE**<br>In the **\<Stack>** component, this attribute has the same effect as **alignContent**, which means that it sets the alignment mode of child components in the container.|
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci## direction
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_cidirection(value: Direction)
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ciSets how elements are laid out along the main axis of the container.
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci**Parameters**
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci| Name| Type                                       | Mandatory| Description                                               |
42e41f4b71Sopenharmony_ci| ------ | ------------------------------------------- | ---- | --------------------------------------------------- |
43e41f4b71Sopenharmony_ci| value  | [Direction](ts-appendix-enums.md#direction) | Yes  | How elements are laid out along the main axis of the container.<br>If this parameter is set to **auto**, the layout is subject to the system language.<br>The attribute does not take effect in the **\<Column>** component.<br>Default value: **Direction.Auto**|
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci## position
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ciposition(value: Position | Edges | LocalizedEdges)
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ciSets the absolute position of the component relative to the position of the parent component.
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci**Parameters**
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci| Name| Type                                                        | Mandatory| Description                                                        |
60e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
61e41f4b71Sopenharmony_ci| value  | [Position](ts-types.md#position) \| [Edges<sup>12+</sup>](ts-types.md#edges12) \| [LocalizedEdges<sup>12+</sup>](ts-types.md#localizededges12) | Yes  | Absolute position of the component relative to the position of the parent component. If the parent container is **\<Row>**, **\<Column>**, or **\<Flex>**, the child component for which **position** is set does not take up space in the container.<br>If of the Position type, this parameter sets the position based on the upper left corner of the parent component. If of the Edges type, this parameter sets the position based on the offset relative to the four edges of the parent component. If of the LocalizedEdges type, this parameter sets the position based on the offset relative to the four edges of the parent component, with support for the mirror mode.<br>The **position** attribute is applicable to scenarios where the component's position in the parent container is fixed, for example, where it is pinned to top or floating on the UI.<br>The attribute is not available for a layout container whose width and height are zero.<br>The attribute does not take effect when the component is in a [\<RelativeContainer>](ts-container-relativecontainer.md) component and with the **alignRules** attribute set.|
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci## markAnchor
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_cimarkAnchor(value: Position | LocalizedPosition)
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ciSets the anchor for locating the component.
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci**Parameters**
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci| Name| Type                            | Mandatory| Description                                                        |
78e41f4b71Sopenharmony_ci| ------ | -------------------------------- | ---- | ------------------------------------------------------------ |
79e41f4b71Sopenharmony_ci| value  | [Position](ts-types.md#position) \| [LocalizedPosition<sup>12+</sup>](ts-types.md#localizedposition12) | Yes  | Anchor for locating the component, which is used to move the component further away from the position specified by **position** or **offset**.<br>**.position({x: value1, y: value2}).markAnchor({x: value3, y: value4})** has the same effect as **.position({x: value1 - value3, y: value2 - value4})**. The same applies to **offset**.<br>When **markAnchor** is used alone, **markAnchor ({x: value1, y: value2})** has the same effect as **.offset ({x: -value1, y: -value2})**.<br>The default value varies by API version.<br>API version 9 and earlier:<br>{<br>x: 0,<br>y: 0<br>}<br>API version 10: none|
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci## offset
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_cioffset(value: Position | Edges | LocalizedEdges)
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ciSets the offset of the component relative to its original position.
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci**Parameters**
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci| Name| Type                                                        | Mandatory| Description                                                        |
96e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
97e41f4b71Sopenharmony_ci| value  | [Position](ts-types.md#position) \| [Edges<sup>12+</sup>](ts-types.md#edges12)  \| [LocalizedEdges<sup>12+</sup>](ts-types.md#localizededges12) | Yes  | Offset of the component relative to its original position. The **offset** attribute does not affect the layout of the parent container. It adjusts the component position only during drawing.<br>If of the Position type, this parameter sets the offset relative to the upper left corner of the component. If of the Edges type, this parameter sets the offset relative to the four edges of the component. **{x: x, y: y}** has the same effect as **{left: x, top: y}** and **{right: -x, bottom: -y}**. The LocalizedEdges type supports the mirror mode: **start** is equivalent to **x** with left-to-right scripts and **-x** with right-to-left scripts.<br>The default value varies by API version.<br>API version 9 and earlier:<br>{<br>x: 0,<br>y: 0<br>}<br>API version 10: none|
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci## alignRules<sup>9+</sup>
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_cialignRules(value: AlignRuleOption)
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ciSets the alignment rules in the relative container. This API is valid only when the container is [\<RelativeContainer>](ts-container-relativecontainer.md).
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci**Parameters**
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci| Name| Type                                       | Mandatory| Description                    |
114e41f4b71Sopenharmony_ci| ------ | ------------------------------------------- | ---- | ------------------------ |
115e41f4b71Sopenharmony_ci| value  | [AlignRuleOption](#alignruleoption) | Yes  | Alignment rules in the relative container.|
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci## alignRules<sup>12+</sup>
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_cialignRules(alignRule: LocalizedAlignRuleOptions)
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ciSets the alignment rules in the relative container. This API is valid only when the container is [\<RelativeContainer>](ts-container-relativecontainer.md). This API takes the right-to-left scripts into account, using **start** and **end** instead of **left** and **right** for alignment in the horizontal direction. Prioritize this API in aligning child components in the relative container.
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci**Parameters**
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci| Name| Type                                       | Mandatory| Description                    |
132e41f4b71Sopenharmony_ci| ------ | ------------------------------------------- | ---- | ------------------------ |
133e41f4b71Sopenharmony_ci| alignRule  | [LocalizedAlignRuleOptions](#localizedalignruleoptions12) | Yes  | Alignment rules in the relative container.|
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci## AlignRuleOption
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci| Name  | Type                                                        | Description                                                        |
140e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
141e41f4b71Sopenharmony_ci| left   | { anchor: string, align: [HorizontalAlign](ts-appendix-enums.md#horizontalalign) } | Left alignment.<br>- **anchor**: ID of the component that functions as the anchor point.<br>- **align**: alignment mode relative to the anchor component.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
142e41f4b71Sopenharmony_ci| right  | { anchor: string, align: [HorizontalAlign](ts-appendix-enums.md#horizontalalign) } | Right alignment.<br>- **anchor**: ID of the component that functions as the anchor point.<br>- **align**: alignment mode relative to the anchor component.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
143e41f4b71Sopenharmony_ci| middle | { anchor: string, align: [HorizontalAlign](ts-appendix-enums.md#horizontalalign) } | Horizontal center alignment.<br>- **anchor**: ID of the component that functions as the anchor point.<br>- **align**: alignment mode relative to the anchor component.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
144e41f4b71Sopenharmony_ci| top    | { anchor: string, align: [VerticalAlign](ts-appendix-enums.md#verticalalign) } | Top alignment.<br>- **anchor**: ID of the component that functions as the anchor point.<br>- **align**: alignment mode relative to the anchor component.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
145e41f4b71Sopenharmony_ci| bottom | { anchor: string, align: [VerticalAlign](ts-appendix-enums.md#verticalalign) } | Bottom alignment.<br>- **anchor**: ID of the component that functions as the anchor point.<br>- **align**: alignment mode relative to the anchor component.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
146e41f4b71Sopenharmony_ci| center | { anchor: string, align: [VerticalAlign](ts-appendix-enums.md#verticalalign) } | Vertical center alignment.<br>**Atomic service API**: This API can be used in atomic services since API version 11.                                |
147e41f4b71Sopenharmony_ci| bias<sup>11+</sup>   | [Bias](#bias) | Offset of the component under the anchor constraints. The value is the ratio of the distance to the left/upper anchor to the total distance between anchors.<br>**Widget capability**: This API can be used in ArkTS widgets since API version 11.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ci## LocalizedAlignRuleOptions<sup>12+</sup>
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci| Name  | Type                                                        | Description                                                        |
154e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
155e41f4b71Sopenharmony_ci| start  | [LocalizedHorizontalAlignParam](#localizedhorizontalalignparam12) | Left alignment with left-to-right scripts and right alignment with right-to-left scripts in the horizontal direction.|
156e41f4b71Sopenharmony_ci| end    | [LocalizedHorizontalAlignParam](#localizedhorizontalalignparam12) | Right alignment with left-to-right scripts and left alignment with right-to-left scripts in the horizontal direction.|
157e41f4b71Sopenharmony_ci| middle | [LocalizedHorizontalAlignParam](#localizedhorizontalalignparam12) | Center alignment in the horizontal direction.|
158e41f4b71Sopenharmony_ci| top    | [LocalizedVerticalAlignParam](#localizedverticalalignparam12) | Top alignment in the vertical direction.|
159e41f4b71Sopenharmony_ci| bottom | [LocalizedVerticalAlignParam](#localizedverticalalignparam12) | Bottom alignment in the vertical direction.|
160e41f4b71Sopenharmony_ci| center | [LocalizedVerticalAlignParam](#localizedverticalalignparam12) | Center alignment in the vertical direction.     |
161e41f4b71Sopenharmony_ci| bias   | [Bias](#bias) | Offset of the component under the anchor constraints. The value is the ratio of the distance to the left/upper anchor to the total distance between anchors.|
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci## LocalizedHorizontalAlignParam<sup>12+</sup>
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
166e41f4b71Sopenharmony_ci
167e41f4b71Sopenharmony_ci| Name  | Type                                                        | Description                                                        |
168e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
169e41f4b71Sopenharmony_ci| anchor  | string  | ID of the component that serves as the anchor.|
170e41f4b71Sopenharmony_ci| align   | [HorizontalAlign](ts-appendix-enums.md#horizontalalign)  | Horizontal alignment mode relative to the anchor component.|
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci## LocalizedVerticalAlignParam<sup>12+</sup>
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci| Name  | Type                                                        | Description                                                        |
177e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
178e41f4b71Sopenharmony_ci| anchor  | string | ID of the component that serves as the anchor.|
179e41f4b71Sopenharmony_ci| align   | [VerticalAlign](ts-appendix-enums.md#verticalalign)  | Vertical alignment mode relative to the anchor component.|
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci## Bias
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ci| Name  | Type                                      | Mandatory  | Description                                      |
186e41f4b71Sopenharmony_ci| ----- | ---------------------------------------- | ---- | ---------------------------------------- |
187e41f4b71Sopenharmony_ci| horizontal  | number | No| Bias value in the horizontal direction.<br>This parameter takes effect when the child component has a determinable width and two horizontal anchors.<br>Default value: **0.5**|
188e41f4b71Sopenharmony_ci| vertical  | number | No| Bias value in the vertical direction.<br>This parameter takes effect when the child component has a determinable height and two vertical anchors.<br>Default value: **0.5**|
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci## chainMode<sup>12+</sup>
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_cichainMode(direction: Axis, style: ChainStyle)
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ciSets the parameters of the chain in which the component is the head. This parameter has effect only when the parent container is [\<RelativeContainer>](ts-container-relativecontainer.md).
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci**Parameters**
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci| Name| Type                                       | Mandatory| Description                    |
201e41f4b71Sopenharmony_ci| ------ | ------------------------------------------- | ---- | ------------------------ |
202e41f4b71Sopenharmony_ci| direction  | [Axis](ts-appendix-enums.md#axis) | Yes  | Direction of the chain.|
203e41f4b71Sopenharmony_ci| style  | [ChainStyle](ts-appendix-enums.md#chainstyle12) | Yes  | Style of the chain.|
204e41f4b71Sopenharmony_ci
205e41f4b71Sopenharmony_ci## Example
206e41f4b71Sopenharmony_ci### Example 1
207e41f4b71Sopenharmony_ci```ts
208e41f4b71Sopenharmony_ci// xxx.ets
209e41f4b71Sopenharmony_ci@Entry
210e41f4b71Sopenharmony_ci@Component
211e41f4b71Sopenharmony_cistruct PositionExample1 {
212e41f4b71Sopenharmony_ci  build() {
213e41f4b71Sopenharmony_ci    Column() {
214e41f4b71Sopenharmony_ci      Column({ space: 10 }) {
215e41f4b71Sopenharmony_ci        // When the component content is within the area specified by the component width and height, set the alignment mode of the content in the component.
216e41f4b71Sopenharmony_ci        Text('align').fontSize(9).fontColor(0xCCCCCC).width('90%')
217e41f4b71Sopenharmony_ci        Stack() {
218e41f4b71Sopenharmony_ci          Text('First show in bottom end').height('65%').backgroundColor(0xD2B48C)
219e41f4b71Sopenharmony_ci          Text('Second show in bottom end').backgroundColor(0xF5DEB3).opacity(0.9)
220e41f4b71Sopenharmony_ci        }.width('90%').height(50).margin({ top: 5 }).backgroundColor(0xFFE4C4)
221e41f4b71Sopenharmony_ci        .align(Alignment.BottomEnd)
222e41f4b71Sopenharmony_ci        Stack() {
223e41f4b71Sopenharmony_ci          Text('top start')
224e41f4b71Sopenharmony_ci        }.width('90%').height(50).margin({ top: 5 }).backgroundColor(0xFFE4C4)
225e41f4b71Sopenharmony_ci        .align(Alignment.TopStart)
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ci        // To arrange the child components from left to right, set direction of the parent container to Direction.Ltr.
228e41f4b71Sopenharmony_ci        Text('direction').fontSize(9).fontColor(0xCCCCCC).width('90%')
229e41f4b71Sopenharmony_ci        Row() {
230e41f4b71Sopenharmony_ci          Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3)
231e41f4b71Sopenharmony_ci          Text('2').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C)
232e41f4b71Sopenharmony_ci          Text('3').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3)
233e41f4b71Sopenharmony_ci          Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C)
234e41f4b71Sopenharmony_ci        }
235e41f4b71Sopenharmony_ci        .width('90%')
236e41f4b71Sopenharmony_ci        .direction(Direction.Ltr)
237e41f4b71Sopenharmony_ci        // To arrange the child components from right to left, set direction of the parent container to Direction.Rtl.
238e41f4b71Sopenharmony_ci        Row() {
239e41f4b71Sopenharmony_ci          Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3).textAlign(TextAlign.End)
240e41f4b71Sopenharmony_ci          Text('2').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C).textAlign(TextAlign.End)
241e41f4b71Sopenharmony_ci          Text('3').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3).textAlign(TextAlign.End)
242e41f4b71Sopenharmony_ci          Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C).textAlign(TextAlign.End)
243e41f4b71Sopenharmony_ci        }
244e41f4b71Sopenharmony_ci        .width('90%')
245e41f4b71Sopenharmony_ci        .direction(Direction.Rtl)
246e41f4b71Sopenharmony_ci      }
247e41f4b71Sopenharmony_ci    }
248e41f4b71Sopenharmony_ci    .width('100%').margin({ top: 5 })
249e41f4b71Sopenharmony_ci  }
250e41f4b71Sopenharmony_ci}
251e41f4b71Sopenharmony_ci```
252e41f4b71Sopenharmony_ci
253e41f4b71Sopenharmony_ci![align.png](figures/align.png)
254e41f4b71Sopenharmony_ci
255e41f4b71Sopenharmony_ci### Example 2
256e41f4b71Sopenharmony_ci```ts
257e41f4b71Sopenharmony_ci// xxx.ets
258e41f4b71Sopenharmony_ci@Entry
259e41f4b71Sopenharmony_ci@Component
260e41f4b71Sopenharmony_cistruct PositionExample2 {
261e41f4b71Sopenharmony_ci  build() {
262e41f4b71Sopenharmony_ci    Column({ space: 20 }) {
263e41f4b71Sopenharmony_ci      // Set the offset of the component's upper left corner relative to the parent component's upper left corner.
264e41f4b71Sopenharmony_ci      Text('position').fontSize(12).fontColor(0xCCCCCC).width('90%')
265e41f4b71Sopenharmony_ci      Row() {
266e41f4b71Sopenharmony_ci        Text('1').size({ width: '30%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16)
267e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Center)
268e41f4b71Sopenharmony_ci        Text('2 position(30, 10)')
269e41f4b71Sopenharmony_ci          .size({ width: '60%', height: '30' })
270e41f4b71Sopenharmony_ci          .backgroundColor(0xbbb2cb)
271e41f4b71Sopenharmony_ci          .border({ width: 1 })
272e41f4b71Sopenharmony_ci          .fontSize(16)
273e41f4b71Sopenharmony_ci          .align(Alignment.Start)
274e41f4b71Sopenharmony_ci          .position({ x: 30, y: 10 })
275e41f4b71Sopenharmony_ci        Text('3').size({ width: '45%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16)
276e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Center)
277e41f4b71Sopenharmony_ci        Text('4 position(50%, 70%)')
278e41f4b71Sopenharmony_ci          .size({ width: '50%', height: '50' })
279e41f4b71Sopenharmony_ci          .backgroundColor(0xbbb2cb)
280e41f4b71Sopenharmony_ci          .border({ width: 1 })
281e41f4b71Sopenharmony_ci          .fontSize(16)
282e41f4b71Sopenharmony_ci          .position({ x: '50%', y: '70%' })
283e41f4b71Sopenharmony_ci      }.width('90%').height(100).border({ width: 1, style: BorderStyle.Dashed })
284e41f4b71Sopenharmony_ci
285e41f4b71Sopenharmony_ci      // Offset relative to the start point. x indicates the horizontal distance between the end point and the start point. If the value of x is greater than 0, the component is offset to the left. Otherwise, the component is offset to the right.
286e41f4b71Sopenharmony_ci      // y indicates the vertical distance between the end point and the start point. If the value of y is greater than 0, the component is offset to the top. Otherwise, the component is offset to the bottom.
287e41f4b71Sopenharmony_ci      Text('markAnchor').fontSize(12).fontColor(0xCCCCCC).width('90%')
288e41f4b71Sopenharmony_ci      Stack({ alignContent: Alignment.TopStart }) {
289e41f4b71Sopenharmony_ci        Row()
290e41f4b71Sopenharmony_ci          .size({ width: '100', height: '100' })
291e41f4b71Sopenharmony_ci          .backgroundColor(0xdeb887)
292e41f4b71Sopenharmony_ci        Text('text')
293e41f4b71Sopenharmony_ci          .fontSize('30px')
294e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Center)
295e41f4b71Sopenharmony_ci          .size({ width: 25, height: 25 })
296e41f4b71Sopenharmony_ci          .backgroundColor(Color.Green)
297e41f4b71Sopenharmony_ci          .markAnchor({ x: 25, y: 25 })
298e41f4b71Sopenharmony_ci        Text('text')
299e41f4b71Sopenharmony_ci          .fontSize('30px')
300e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Center)
301e41f4b71Sopenharmony_ci          .size({ width: 25, height: 25 })
302e41f4b71Sopenharmony_ci          .backgroundColor(Color.Green)
303e41f4b71Sopenharmony_ci          .markAnchor({ x: -100, y: -25 })
304e41f4b71Sopenharmony_ci        Text('text')
305e41f4b71Sopenharmony_ci          .fontSize('30px')
306e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Center)
307e41f4b71Sopenharmony_ci          .size({ width: 25, height: 25 })
308e41f4b71Sopenharmony_ci          .backgroundColor(Color.Green)
309e41f4b71Sopenharmony_ci          .markAnchor({ x: 25, y: -25 })
310e41f4b71Sopenharmony_ci      }.margin({ top: 25 }).border({ width: 1, style: BorderStyle.Dashed })
311e41f4b71Sopenharmony_ci
312e41f4b71Sopenharmony_ci      // Offset of the component relative to itself. If the value of x is greater than 0, the component is offset to the right. Otherwise, the component is offset to the left. If the value of y is greater than 0, the component is offset to the bottom. Otherwise, the component is offset to the top.
313e41f4b71Sopenharmony_ci      Text('offset').fontSize(12).fontColor(0xCCCCCC).width('90%')
314e41f4b71Sopenharmony_ci      Row() {
315e41f4b71Sopenharmony_ci        Text('1').size({ width: '15%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16)
316e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Center)
317e41f4b71Sopenharmony_ci        Text('2  offset(15, 30)')
318e41f4b71Sopenharmony_ci          .size({ width: 120, height: '50' })
319e41f4b71Sopenharmony_ci          .backgroundColor(0xbbb2cb)
320e41f4b71Sopenharmony_ci          .border({ width: 1 })
321e41f4b71Sopenharmony_ci          .fontSize(16)
322e41f4b71Sopenharmony_ci          .align(Alignment.Start)
323e41f4b71Sopenharmony_ci          .offset({ x: 15, y: 30 })
324e41f4b71Sopenharmony_ci        Text('3').size({ width: '15%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16)
325e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Center)
326e41f4b71Sopenharmony_ci        Text('4 offset(-5%, 20%)')
327e41f4b71Sopenharmony_ci          .size({ width: 100, height: '50' })
328e41f4b71Sopenharmony_ci          .backgroundColor(0xbbb2cb)
329e41f4b71Sopenharmony_ci          .border({ width: 1 })
330e41f4b71Sopenharmony_ci          .fontSize(16)
331e41f4b71Sopenharmony_ci          .offset({ x: '-5%', y: '20%' })
332e41f4b71Sopenharmony_ci      }.width('90%').height(100).border({ width: 1, style: BorderStyle.Dashed })
333e41f4b71Sopenharmony_ci    }
334e41f4b71Sopenharmony_ci    .width('100%').margin({ top: 25 })
335e41f4b71Sopenharmony_ci  }
336e41f4b71Sopenharmony_ci}
337e41f4b71Sopenharmony_ci```
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_ci![position.png](figures/position.png)
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_ci### Example 3
342e41f4b71Sopenharmony_ci```ts
343e41f4b71Sopenharmony_ci// xxx.ets
344e41f4b71Sopenharmony_ci@Entry
345e41f4b71Sopenharmony_ci@Component
346e41f4b71Sopenharmony_cistruct Example3 {
347e41f4b71Sopenharmony_ci  build() {
348e41f4b71Sopenharmony_ci    Column({ space: 20 }){
349e41f4b71Sopenharmony_ci      Text('position use Edges').fontSize(12).fontColor(0xCCCCCC).width('90%')
350e41f4b71Sopenharmony_ci      Row() {
351e41f4b71Sopenharmony_ci        Text('bottom:0, right:0').size({ width: '30%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16)
352e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Center).position({bottom: 0, right: 0})
353e41f4b71Sopenharmony_ci        Text('top:0, left:0').size({ width: '30%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16)
354e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Center).position({top: 0, left: 0})
355e41f4b71Sopenharmony_ci        Text('top:10%, left:50%').size({ width: '50%', height: '30' }).backgroundColor(0xbbb2cb).border({ width: 1 }).fontSize(16)
356e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Center).position({ top: '10%', left: '50%' })
357e41f4b71Sopenharmony_ci        Text('bottom:0, left:30').size({ width: '50%', height: '30' }).backgroundColor(0xbbb2cb).border({ width: 1 }).fontSize(16)
358e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Center).position({ bottom: 0, left: 30 })
359e41f4b71Sopenharmony_ci      }.width('90%').height(100).border({ width: 1, style: BorderStyle.Dashed })
360e41f4b71Sopenharmony_ci
361e41f4b71Sopenharmony_ci
362e41f4b71Sopenharmony_ci      Text('offset use Edges').fontSize(12).fontColor(0xCCCCCC).width('90%')
363e41f4b71Sopenharmony_ci      Row() {
364e41f4b71Sopenharmony_ci        Text('1').size({ width: '25%', height: 50 }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16)
365e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Center)
366e41f4b71Sopenharmony_ci        Text('2 top:30, left:0').size({ width: '25%', height: 50 }).backgroundColor(0xbbb2cb).border({ width: 1 }).fontSize(16)
367e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Center).offset({top: 30, left: 0})
368e41f4b71Sopenharmony_ci        Text('3').size({ width: '25%', height: 50 }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16)
369e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Center)
370e41f4b71Sopenharmony_ci        Text('4 bottom:10, right:30').size({ width: '25%', height: 50 }).backgroundColor(0xbbb2cb).border({ width: 1 }).fontSize(12)
371e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Center).offset({bottom: 10, right: 30})
372e41f4b71Sopenharmony_ci      }.width('90%').height(150).border({ width: 1, style: BorderStyle.Dashed })
373e41f4b71Sopenharmony_ci    }.width('100%').margin({ top: 25 })
374e41f4b71Sopenharmony_ci  }
375e41f4b71Sopenharmony_ci}
376e41f4b71Sopenharmony_ci```
377e41f4b71Sopenharmony_ci
378e41f4b71Sopenharmony_ci![position.png](figures/position2.jpeg)
379e41f4b71Sopenharmony_ci
380e41f4b71Sopenharmony_ci### Example 4
381e41f4b71Sopenharmony_ci```ts
382e41f4b71Sopenharmony_ci// xxx.ets 
383e41f4b71Sopenharmony_ci// The mirror mode is supported.
384e41f4b71Sopenharmony_ci// The example shows the configuration effects of the **position**, **offset**, and **markAnchor** attributes, from top to bottom.
385e41f4b71Sopenharmony_ci// The yellow blocks indicate the original effect, and the pink blocks indicate the mirror effect.
386e41f4b71Sopenharmony_ciimport { LengthMetrics } from '@kit.ArkUI';
387e41f4b71Sopenharmony_ci@Entry
388e41f4b71Sopenharmony_ci@Component
389e41f4b71Sopenharmony_cistruct Example4 {
390e41f4b71Sopenharmony_ci  private scroller: Scroller = new Scroller()
391e41f4b71Sopenharmony_ci
392e41f4b71Sopenharmony_ci  build() {
393e41f4b71Sopenharmony_ci    Column() {
394e41f4b71Sopenharmony_ci      Stack({ alignContent: Alignment.End }) {
395e41f4b71Sopenharmony_ci        Scroll(this.scroller) {
396e41f4b71Sopenharmony_ci          Flex({ direction: FlexDirection.Column }) {
397e41f4b71Sopenharmony_ci            RelativeContainer() {
398e41f4b71Sopenharmony_ci              Row() {
399e41f4b71Sopenharmony_ci              }
400e41f4b71Sopenharmony_ci              .position({ start: LengthMetrics.px(200), top: LengthMetrics.px(100) })
401e41f4b71Sopenharmony_ci              .width("30%")
402e41f4b71Sopenharmony_ci              .height("20%")
403e41f4b71Sopenharmony_ci              .backgroundColor(Color.Pink)
404e41f4b71Sopenharmony_ci              .padding(50)
405e41f4b71Sopenharmony_ci              .margin(50)
406e41f4b71Sopenharmony_ci              Row() {
407e41f4b71Sopenharmony_ci              }
408e41f4b71Sopenharmony_ci              .position({ left:'200px', top: '100px' })
409e41f4b71Sopenharmony_ci              .width("30%")
410e41f4b71Sopenharmony_ci              .height("20%")
411e41f4b71Sopenharmony_ci              .backgroundColor(Color.Yellow)
412e41f4b71Sopenharmony_ci              .padding(50)
413e41f4b71Sopenharmony_ci              .margin(50)
414e41f4b71Sopenharmony_ci              Row() {
415e41f4b71Sopenharmony_ci              }
416e41f4b71Sopenharmony_ci              .offset({ start: LengthMetrics.vp(100), top: LengthMetrics.vp(200)  })
417e41f4b71Sopenharmony_ci              .width("30%")
418e41f4b71Sopenharmony_ci              .height("20%")
419e41f4b71Sopenharmony_ci              .backgroundColor(Color.Pink)
420e41f4b71Sopenharmony_ci              .padding(50)
421e41f4b71Sopenharmony_ci              .margin(50)
422e41f4b71Sopenharmony_ci              Row() {
423e41f4b71Sopenharmony_ci              }
424e41f4b71Sopenharmony_ci              .offset({ left: 100, top: 200  })
425e41f4b71Sopenharmony_ci              .width("30%")
426e41f4b71Sopenharmony_ci              .height("20%")
427e41f4b71Sopenharmony_ci              .backgroundColor(Color.Yellow)
428e41f4b71Sopenharmony_ci              .padding(50)
429e41f4b71Sopenharmony_ci              .margin(50)
430e41f4b71Sopenharmony_ci              Row() {
431e41f4b71Sopenharmony_ci              }
432e41f4b71Sopenharmony_ci              .markAnchor({ start: LengthMetrics.fp(100), top: LengthMetrics.fp(-350) })
433e41f4b71Sopenharmony_ci              .width("30%")
434e41f4b71Sopenharmony_ci              .height("20%")
435e41f4b71Sopenharmony_ci              .backgroundColor(Color.Pink)
436e41f4b71Sopenharmony_ci              .padding(50)
437e41f4b71Sopenharmony_ci              .margin(50)
438e41f4b71Sopenharmony_ci              Row() {
439e41f4b71Sopenharmony_ci              }
440e41f4b71Sopenharmony_ci              .markAnchor({ x: '100fp', y: '-350fp' })
441e41f4b71Sopenharmony_ci              .width("30%")
442e41f4b71Sopenharmony_ci              .height("20%")
443e41f4b71Sopenharmony_ci              .backgroundColor(Color.Yellow)
444e41f4b71Sopenharmony_ci              .padding(50)
445e41f4b71Sopenharmony_ci              .margin(50)
446e41f4b71Sopenharmony_ci            }
447e41f4b71Sopenharmony_ci            .backgroundColor(Color.White)
448e41f4b71Sopenharmony_ci            .padding(50)
449e41f4b71Sopenharmony_ci            .margin(50)
450e41f4b71Sopenharmony_ci          }
451e41f4b71Sopenharmony_ci        }
452e41f4b71Sopenharmony_ci        .width('100%')
453e41f4b71Sopenharmony_ci        .scrollBar(BarState.Off)
454e41f4b71Sopenharmony_ci        .scrollable(ScrollDirection.Vertical)
455e41f4b71Sopenharmony_ci
456e41f4b71Sopenharmony_ci        ScrollBar({ scroller: this.scroller, direction: ScrollBarDirection.Vertical, state: BarState.Auto }) {
457e41f4b71Sopenharmony_ci          Text()
458e41f4b71Sopenharmony_ci            .width(20)
459e41f4b71Sopenharmony_ci            .height(100)
460e41f4b71Sopenharmony_ci            .borderRadius(10)
461e41f4b71Sopenharmony_ci            .backgroundColor('#C0C0C0')
462e41f4b71Sopenharmony_ci        }.width(20).backgroundColor('#ededed')
463e41f4b71Sopenharmony_ci      }
464e41f4b71Sopenharmony_ci    }.height('90%')
465e41f4b71Sopenharmony_ci  }
466e41f4b71Sopenharmony_ci}
467e41f4b71Sopenharmony_ci```
468e41f4b71Sopenharmony_ci![position.png](figures/position3.png)
469