水平方向布局容器

2024-01-22 17:56 更新

沿水平方向布局容器。

說明

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

子組件

可以包含子組件。

接口

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

從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時不生效。

默認(rèn)值:0,單位vp

說明:

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

屬性

名稱

參數(shù)類型

描述

alignItems

VerticalAlign

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

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

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

justifyContent8+

FlexAlign

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

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

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

示例

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

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

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號