Note: To access all shared projects, get information about environment setup, and view other guides, please visit Explore-In-HMOS-Wearable Index.
A wearable codelab app for the ArkUI Flex container. A round-screen swiper routes to three full-screen pages, each
isolating one axis of Flex behaviour: AxisPage (distributing leftover space), AdaptPage (running out of space),
and WrapPage (multi-line flow). Shared tile faces come from global @Builder functions so every page renders an
identical metric card.
- Swipe through three Flex demos, each one full-screen and self-contained.
- AxisPage — split leftover main-axis space by
flexGrowratio (2:1 and 1:1:1), and flip reading order withFlexDirection.RowReverse. Tap a support tile to promote it to hero. - AdaptPage — squeeze a metric strip with a slider and watch it degrade: tiles yield width by
flexShrinkweight, stop at aconstraintSizefloor, then drop bydisplayPriority. Tap a tile to pin it. - WrapPage — reflow activity chips across lines with
FlexWrap.Wrap, adjust the chip count, and toggle gap density viaspace.main/space.cross. - Round-screen navigation — hand-drawn page crumbs replace the native Swiper indicator, which the circular bezel clips.
- Languages: ArkTS, ArkUI
- Frameworks: HarmonyOS SDK 5.1.0(18)+, API 23 and below
- Tools: DevEco Studio Version 5.1.0.828+
- Libraries:
@kit.ArkUI(UI Components & Layouts —LengthMetrics)
Container properties (passed to the Flex({ ... }) constructor):
direction— which way tiles line up. Left-to-right everywhere;RowReverseflips AxisPage around.justifyContent— where tiles sit along the row when there is space left over.alignItems— how tiles line up top-to-bottom. Centred for tile rows, full-height for the AdaptPage strip.wrap— lets WrapPage chips drop to a new line instead of being squeezed.alignContent— spreads those wrapped lines evenly down the screen.space— the gap between tiles.mainalong the row,crossbetween lines on WrapPage.
Child properties (chained onto children of a Flex):
flexGrow— how big a share of the row each tile takes. 2 makes a tile twice as wide as 1.flexBasis— the width a tile asks for before growing or shrinking.0on AxisPage.flexShrink— how readily a tile gives up width when the row gets tight.0means it never does.displayPriority— which tile disappears first once nothing more can be given up.alignSelf— lets one pinned tile ignore the row's vertical alignment and stretch full-height.constraintSize— the smallest width a tile will accept. It stops shrinking here. |
- Set
flexBasis(0)before usingflexGrow. Otherwise the ratio only splits the space left over after each tile's natural width, so a 2:1 ratio does not actually look 2:1. - Shrinking has to stop before dropping can start. With
flexShrinkalone tiles just keep getting narrower and the row never runs out of room, sodisplayPrioritynever comes into play. AconstraintSizeminimum width is what puts the brakes on. Worth checking on a real watch, not just the Previewer. - Global
@Builderfunctions live inMetricCommon.etsoutside any struct and are called withoutthis., so all three pages share the same tile face.
FlexCodelab
|--- entry/src/main/ets/
| |--- pages/
| | |--- Index.ets # Swiper host and page routing
| |
| |--- view/
| | |--- AxisPage.ets # flexGrow / flexBasis / FlexDirection demo
| | |--- AdaptPage.ets # flexShrink / displayPriority / alignSelf demo
| | |--- WrapPage.ets # FlexWrap / alignContent / space demo
| | |--- MetricCommon.ets # Global Builders and per-key config functions
| |
| |--- model/
| | |--- HealthData.ets # Metric type and sample data
| | |--- Theme.ets # Color and radius tokens
|--- screenshots/ # UI Preview images for documentation
- Huawei Watch 5
- HarmonyOS wearable emulator (UI, navigation, web page, lifecycle logs)
- Targets API 23 and below.
flexShrinkdefaults to1under aFlexparent but0underRow/Column. This is the most common cause of a layout changing when the container is swapped.Flexresolves grow/shrink with an extra measure pass, so it is slower thanRow/Column. Prefer the simpler containers where the resolution is not needed.
FlexCodelab is distributed under the terms of the MIT License. See the LICENSE for more information.


