Read the original article:Four-Corner Text Placement in a Stack (ArkUI)
Four-Corner Text Placement in a Stack (ArkUI)
Requirement Description
Place four Text components at the top-left, top-right, bottom-left, and bottom-right corners within a Stack.
Background Knowledge
-
justifyContentaligns children along the main axis forRow/Column. See -
Stackprovides layered layout and fixed positioning space. See
Implementation Steps
- Use a
Stackas the container and stretch it to fill its parent. - Inside the
Stack, place aColumnthat has twoRows:- The first
Rowholds the top-left and top-right texts; setjustifyContent(FlexAlign.SpaceBetween)andwidth('100%'). - The second
Rowholds the bottom-left and bottom-right texts; set the same properties.
- The first
- Space the two
Rows vertically by applyingjustifyContent(FlexAlign.SpaceBetween)on the parentColumnand give itheight('100%'). - (Wearables) Keep sizes in
vp, avoid absolute pixel offsets, and respect safe areas for round screens.
Code Snippet / Configuration
@Entry
@Component
struct Index {
build() {
Stack({ alignContent: Alignment.Center }) {
Column() {
Row() {
Text('Top-Left')
.fontSize('9.00fp')
.fontColor(Color.Red)
Text('Top-Right')
.fontSize('9.00fp')
.fontColor(Color.Red)
}
.width('100%')
.justifyContent(FlexAlign.SpaceBetween)
Row() {
Text('Bottom-Left')
.fontSize('9.00fp')
.fontColor(Color.Red)
Text('Bottom-Right')
.fontSize('9.00fp')
.fontColor(Color.Red)
}
.width('100%')
.justifyContent(FlexAlign.SpaceBetween)
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.SpaceBetween)
// For wearables, consider safe area if needed:
// .safeArea({ type: SafeAreaType.SYSTEM, edges: [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM] })
}
.width('60%')
.height('60%')
.backgroundColor(Color.White)
.margin({
top: "22%",
left: "22%"
})
}
}
Test Results
- Verified that all four
Textnodes anchor to the intended corners on rectangular and round screens (Watch 5) when the parent fills the viewport.
Limitations or Considerations
- SDK / Tools: Works with API Version 19 Release+, HarmonyOS 5.1.1 Release SDK+, DevEco Studio 5.1.1 Release+.
-
Wearables: On round displays, ensure important content stays within visible bounds; consider
safeAreaas shown. - Scaling: If using larger fonts or dynamic content, add padding to avoid clipping.

Top comments (0)