空白填充組件

2024-01-22 17:04 更新

空白填充組件,在容器主軸方向上,空白填充組件具有自動(dòng)填充容器空余部分的能力。僅當(dāng)父組件為Row/Column/Flex時(shí)生效。

說明

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

子組件

接口

Blank(min?: number | string)

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

參數(shù):

參數(shù)名

參數(shù)類型

必填

參數(shù)描述

min

number | string

空白填充組件在容器主軸上的最小大小。

默認(rèn)值:0

說明:

不支持設(shè)置百分比。負(fù)值使用默認(rèn)值。當(dāng)最小值大于容器可用空間時(shí),使用最小值作為自身大小并超出容器。

屬性

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

名稱

參數(shù)類型

描述

color

ResourceColor

設(shè)置空白填充的填充顏色。

默認(rèn)值:Color.Transparent

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

事件

支持通用事件

示例

示例1

Blank組件在橫豎屏占滿空余空間效果。

  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct BlankExample {
  5. build() {
  6. Column() {
  7. Row() {
  8. Text('Bluetooth').fontSize(18)
  9. Blank()
  10. Toggle({ type: ToggleType.Switch }).margin({ top: 14, bottom: 14, left: 6, right: 6 })
  11. }.width('100%').backgroundColor(0xFFFFFF).borderRadius(15).padding({ left: 12 })
  12. }.backgroundColor(0xEFEFEF).padding(20)
  13. }
  14. }

豎屏狀態(tài)

橫屏狀態(tài)

示例2

Blank組件的父組件未設(shè)置寬度時(shí),min參數(shù)的使用效果。

  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct BlankExample {
  5. build() {
  6. Column({ space: 20 }) {
  7. // blank父組件不設(shè)置寬度時(shí),Blank失效,可以通過設(shè)置min最小寬度填充固定寬度
  8. Row() {
  9. Text('Bluetooth').fontSize(18)
  10. Blank().color(Color.Yellow)
  11. Toggle({ type: ToggleType.Switch }).margin({ top: 14, bottom: 14, left: 6, right: 6 })
  12. }.backgroundColor(0xFFFFFF).borderRadius(15).padding({ left: 12 })
  13. Row() {
  14. Text('Bluetooth').fontSize(18)
  15. // 設(shè)置最小寬度為160
  16. Blank('160').color(Color.Yellow)
  17. Toggle({ type: ToggleType.Switch }).margin({ top: 14, bottom: 14, left: 6, right: 6 })
  18. }.backgroundColor(0xFFFFFF).borderRadius(15).padding({ left: 12 })
  19. }.backgroundColor(0xEFEFEF).padding(20).width('100%')
  20. }
  21. }

Blank父組件未設(shè)置寬度時(shí),子組件間無空白填充,使用min參數(shù)設(shè)置填充尺寸

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

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)