使用position定位属性,将A组件脱离标准流,配合zIndex设置A组件的层级将其展示在上层,实现A组件展示在B组件上层的效果。
示例代码如下:
@Entry
@Component
struct ZIndexExample {
build() {
Column() {
Button('A组件')
.width(200)
.height(50)
.fontColor(Color.Black)
.backgroundColor('#d9dadd')
.position({ x: 90, y: 50 })
.zIndex(99)
Column() {
Text('B组件').padding({top:20});
}
.width('90%').height(150).backgroundColor('#f2f3f5').borderRadius(10)
}
.width('100%')
}
} 运行效果图如下:
