说明
层叠布局,一个组件可以 盖住 另一个组件
层叠布局通过 Stack容器 组件,实现位置的定位与层叠,容器中的子元素依次入栈,后一个子元素 覆盖 前一个子元素,子元素可以叠加,也可以设置位置。
应用场景
层叠布局具有较强的页面层叠、位置定位能力,其使用场景有广告、卡片层叠效果等。
例子
后添加 的 按钮,盖住 了 先添加 的文本控件
@Entry
@Component
struct Index {
@State message: string = 'Hello World';
build() {
Stack() {
Text(this.message)
.id('HelloWorld')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button('测试')
.id('HelloWorld')
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.height('100%')
.width('100%')
}
}
