沿垂直方向布局的容器

2024-01-22 17:47 更新
說明

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

子組件

可以包含子組件。

接口

Column(value?: {space?: string | number})

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

參數(shù):

參數(shù)名

參數(shù)類型

必填

參數(shù)描述

space

string | number

縱向布局元素垂直方向間距。

從API version 9開始,space為負(fù)數(shù)或者justifyContent設(shè)置為FlexAlign.SpaceBetween、FlexAlign.SpaceAround、FlexAlign.SpaceEvenly時(shí)不生效。

默認(rèn)值:0

說明:

可選值為大于等于0的數(shù)字,或者可以轉(zhuǎn)換為數(shù)字的字符串。

屬性

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

名稱

參數(shù)類型

描述

alignItems

HorizontalAlign

設(shè)置子組件在水平方向上的對(duì)齊格式。

默認(rèn)值:HorizontalAlign.Center

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

justifyContent8+

FlexAlign

設(shè)置子組件在垂直方向上的對(duì)齊格式。

默認(rèn)值:FlexAlign.Start

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

示例

  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct ColumnExample {
  5. build() {
  6. Column({ space: 5 }) {
  7. // 設(shè)置子元素垂直方向間距為5
  8. Text('space').width('90%')
  9. Column({ space: 5 }) {
  10. Column().width('100%').height(30).backgroundColor(0xAFEEEE)
  11. Column().width('100%').height(30).backgroundColor(0x00FFFF)
  12. }.width('90%').height(100).border({ width: 1 })
  13. // 設(shè)置子元素水平方向?qū)R方式
  14. Text('alignItems(Start)').width('90%')
  15. Column() {
  16. Column().width('50%').height(30).backgroundColor(0xAFEEEE)
  17. Column().width('50%').height(30).backgroundColor(0x00FFFF)
  18. }.alignItems(HorizontalAlign.Start).width('90%').border({ width: 1 })
  19. Text('alignItems(End)').width('90%')
  20. Column() {
  21. Column().width('50%').height(30).backgroundColor(0xAFEEEE)
  22. Column().width('50%').height(30).backgroundColor(0x00FFFF)
  23. }.alignItems(HorizontalAlign.End).width('90%').border({ width: 1 })
  24. Text('alignItems(Center)').width('90%')
  25. Column() {
  26. Column().width('50%').height(30).backgroundColor(0xAFEEEE)
  27. Column().width('50%').height(30).backgroundColor(0x00FFFF)
  28. }.alignItems(HorizontalAlign.Center).width('90%').border({ width: 1 })
  29. // 設(shè)置子元素垂直方向的對(duì)齊方式
  30. Text('justifyContent(Center)').width('90%')
  31. Column() {
  32. Column().width('90%').height(30).backgroundColor(0xAFEEEE)
  33. Column().width('90%').height(30).backgroundColor(0x00FFFF)
  34. }.height(100).border({ width: 1 }).justifyContent(FlexAlign.Center)
  35. Text('justifyContent(End)').width('90%')
  36. Column() {
  37. Column().width('90%').height(30).backgroundColor(0xAFEEEE)
  38. Column().width('90%').height(30).backgroundColor(0x00FFFF)
  39. }.height(100).border({ width: 1 }).justifyContent(FlexAlign.End)
  40. }.width('100%').padding({ top: 5 })
  41. }
  42. }

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

掃描二維碼

下載編程獅App

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

編程獅公眾號(hào)