鸿蒙入门07-Blank组件

空白填充组件

在容器 主轴方向

空白填充组件具有自动填充空余部分的能力

注意 : 仅在父组件为 Row 或者 Column 的时候有效

注意 : 不能使用通用属性修饰

参数

参数名

参数类型

是否必填

默认值

参数描述

min

number | string

0

空白填充组件的最小填充尺寸

相关属性

名称

参数类型

默认值

描述

color

ResourceColor

0xffffff

设置空白填充的颜色

示例 1

@Entry
@Component
struct Index {
  build() {
    Column() {
      // 没有使用 Blank 组件
      Row() {
        Text('左').fontSize(30)
        Text('右').fontSize(30)
      }.width('100%').height(50)

      Divider().height(50)

      // 使用 Blank 组件
      Row() {
        Text('左').fontSize(30)
        Blank()
        Text('右').fontSize(30)
      }.width('100%').height(50)
    }
  }
}

 示例 2

@Entry
@Component
struct Index {
  build() {
    Column() {
      Row() {
        Text('左').fontSize(30)
        Blank()
        Text('右').fontSize(30)
      }.width('100%').height(50)

      Divider().height(50)

      Row() {
        Text('左').fontSize(30)
        Blank()
        Text('中').fontSize(30)
        Blank()
        Text('右').fontSize(30)
      }.width('100%').height(50)
    }
  }
}

示例 3

设置 Blank 组件的参数为 200

不管剩余空白有多少,我最少填充 200 的尺寸

@Entry
  @Component
  struct Index {
    build() {
      Column() {
        Row() {
          Text('左').fontSize(30)
          Blank()
          Text('右').fontSize(30)
        }.width('100%').height(50)

        Divider().height(50)

        Row() {
          Text('左').fontSize(30)
          Blank(200)
          Text('中').fontSize(30)
          Blank(200)
          Text('右').fontSize(30)
        }.width('100%').height(50)
      }
    }
  }

示例 4

还可以通过 color 方法来修饰填充部分的颜色

@Entry
@Component
struct Index {
  build() {
    Column() {
      Row() {
        Text('左').fontSize(30)
        Blank().color(Color.Pink)
        Text('右').fontSize(30)
      }.width('100%').height(50)

      Divider().height(50)

      Row() {
        Text('左').fontSize(30)
        Blank(200).color(Color.Orange)
        Text('中').fontSize(30)
        Blank(200).color(Color.Gray)
        Text('右').fontSize(30)
      }.width('100%').height(50)
    }
  }
}

  • 9
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值