堆疊容器

2024-01-22 17:57 更新

堆疊容器,子組件按照順序依次入棧,后一個子組件覆蓋前一個子組件。

說明

該組件從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標單獨標記該內(nèi)容的起始版本。

子組件

可以包含子組件。

接口

Stack(value?: { alignContent?: Alignment })

從API version 9開始,該接口支持在ArkTS卡片中使用。

參數(shù):

參數(shù)名

參數(shù)類型

必填

參數(shù)描述

alignContent

Alignment

設置子組件在容器內(nèi)的對齊方式。

默認值:Alignment.Center

屬性

除支持通用屬性外,還支持以下屬性:

參數(shù)名

參數(shù)類型

參數(shù)描述

alignContent

Alignment

設置所有子組件在容器內(nèi)的對齊方式。

默認值:Alignment.Center

從API version 9開始,該接口支持在ArkTS卡片中使用。

說明:

該屬性與通用屬性align同時設置時,后設置的屬性生效。

示例

  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct StackExample {
  5. build() {
  6. Stack({ alignContent: Alignment.Bottom }) {
  7. Text('First child, show in bottom').width('90%').height('100%').backgroundColor(0xd2cab3).align(Alignment.Top)
  8. Text('Second child, show in top').width('70%').height('60%').backgroundColor(0xc1cbac).align(Alignment.Top)
  9. }.width('100%').height(150).margin({ top: 5 })
  10. }
  11. }

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號