openharmony容器组件之Stack

Stack:堆叠容器,子组件按照顺序依次入栈,后一个子组件覆盖前一个子组件
Stack(value:{alignContent?: Alignment})
        alignContent:设置子组件在容器内的对齐方式(默认Center)

案例展示:

 代码:

@Entry
@Component
struct StackPage {
  build() {
    Stack({ alignContent: Alignment.Center }) {
      Text('first child,show in Center')
        .width('90%')
        .height('100%')
        .fontSize(20)
        .backgroundColor(0xd2cab3)
        .align(Alignment.Top)
      Text('second child,show in Center')
        .width('70%')
        .height('70%')
        .fontSize(20)
        .backgroundColor(0xc1cbac)
        .align(Alignment.Top)
    }
    .width('100%')
    .height('100%')
  }
}

猜你喜欢

转载自blog.csdn.net/lplj717/article/details/126278525