ZStack
沿深度(Z 轴)层叠渲染多个子视图的容器:后写的元素盖在先写的元素上方,适合背景底图叠加文字、圆环内嵌自定义组件以及右上角状态角标。
签名#
签名
<ZStack alignment="topTrailing">
<Box width={108} height={68}
background="theme.faint"
cornerRadius={14} />
<Badge text="LIVE"
color="theme.success" />
</ZStack>
ZStack · 右上角层叠
LIVE
属性#
继承全部 StyleProps:
alignmentstring默认 "center"- 层叠子视图在容器内的锚点,可选
"center"、"top"、"bottom"、"leading"、"trailing",以及四角组合"topLeading"、"topTrailing"、"bottomLeading"、"bottomTrailing"。 zIndexnumber可选- 写在子节点上,数值越大越靠前(覆盖在数值小的同级元素上方)。
示例:圆环中心叠放文本#
TSX
<ZStack alignment="center">
<Ring value={82} size={96} lineWidth={9}
color="theme.accent" />
<VStack alignment="center" spacing={1}>
<Text fontSize={22} fontWeight="bold">
82%
</Text>
<Text fontSize={11}
color="theme.secondary">Battery</Text>
</VStack>
</ZStack>
圆环居中层叠文字
82%
Battery