【鸿蒙开发】系统组件Row

本文详细介绍了Row组件在UI设计中的用法,包括水平方向的FlexAlign对齐方式(Start、Center、End、SpaceBetween等)以及垂直方向的VerticalAlign(Top、Center、Bottom)。通过实例展示了如何调整元素间距和对齐方式来创建多行布局。
摘要由CSDN通过智能技术生成

Row组件

Row沿水平方向布局容器

接口:

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

参数:

参数名

参数类型

必填

参数描述

space

string | number

横向布局元素间距。

从API version 9开始,space为负数或者justifyContent设置为FlexAlign.SpaceBetween、FlexAlign.SpaceAround、FlexAlign.SpaceEvenly时不生效。

默认值:0,单位vp

说明:

可选值为大于等于0的数字,或者可以转换为数字的字符串。

属性:

名称

参数类型

描述

alignItems

VerticalAlign

设置子组件在垂直方向上的对齐格式。

默认值:VerticalAlign.Center

从API version 9开始,该接口支持在ArkTS卡片中使用。

justifyContent8+

FlexAlign

设置子组件在水平方向上的对齐格式。

默认值:FlexAlign.Start

从API version 9开始,该接口支持在ArkTS卡片中使用。

UI结构示例,1行里包含3行

@Entry
@Component
struct APage {
  build() {
    Row() {
      Row() {
        Text("左部")
          .width('100%')
          .fontColor(Color.White)
          .textAlign(TextAlign.Center)
      }
      .backgroundColor(Color.Red)
      .width(100)
      .height(100)

      Row() {
        Text("中间")
          .width('100%')
          .fontColor(Color.White)
          .textAlign(TextAlign.Center)
      }
      .backgroundColor(Color.Blue)
      .width(100)
      .height(100)

      Row() {
        Text("右部")
          .width('100%')
          .fontColor(Color.White)
          .textAlign(TextAlign.Center)
      }
      .backgroundColor(Color.Pink)
      .width(100)
      .height(100)
    }
    .width('100%')
    .height('100%')
  }
}

水平方向对齐

FlexAlign.Start

@Entry
@Component
struct APage {
  build() {
    Row() {
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Start)
  }
}

FlexAlign.Center

@Entry
@Component
struct APage {
  build() {
    Row() {
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Center)
  }
}

FlexAlign.End

@Entry
@Component
struct APage {
  build() {
    Row() {
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.End)
  }
}

FlexAlign.SpaceBetween

@Entry
@Component
struct APage {
  build() {
    Row() {
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.SpaceBetween)
  }
}

FlexAlign.SpaceAround

@Entry
@Component
struct APage {
  build() {
    Row() {
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.SpaceAround)
  }
}

FlexAlign.SpaceEvenly

@Entry
@Component
struct APage {
  build() {
    Row() {
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.SpaceEvenly)
  }
}

垂直方向对齐

VerticalAlign.Top

@Entry
@Component
struct APage {
  build() {
    Row() {
    }
    .width('100%')
    .height('100%')
    .alignItems(VerticalAlign.Top)
  }
}

VerticalAlign.Center

@Entry
@Component
struct APage {
  build() {
    Row() {
    }
    .width('100%')
    .height('100%')
    .alignItems(VerticalAlign.Center)
  }
}

VerticalAlign.Bottom

@Entry
@Component
struct APage {
  build() {
    Row() {
    }
    .width('100%')
    .height('100%')
    .alignItems(VerticalAlign.Bottom)
  }
}

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值