鸿蒙学习——2、基础组件-Blank

Blank

空白填充组件,在容器主轴方向上,空白填充组件具有自动填充容器空余部分的能力。仅当父组件为Row/Column/Flex 时生效

说明:该组件从API Version7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。

子组件

接口

Blank(min?:number | string)

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

参数:

参数名参数类型必填参数描述
minnumber | string

空白填充组件在容器主轴上的最小大小。

默认值:0

说明:

不支持设置百分比。负值使用默认值。当最小值大于容器可用空间时,使用最小值作为自身大小并超出容器。

属性

除支持通用属性外,还支持以下属性:

名称参数类型描述
colorResourceColor

设置空白填充的填充颜色。

默认值:Color.Transparent
从API version9开始,该接口支持在ArkTs
卡片中使用。

事件

支持通用事件

示例

示例1

Blank组件在横竖屏占满空余空间效果:

@Entry
@Component
struct BlankExample {
  build() {
    Column() {
      Row() {
        Text('Buletooth').fontSize(18)
        Blank()
        Toggle({ type: ToggleType.Switch }).margin({ top: 14, bottom: 14, left: 6, right: 6 })
      }.width("100%").backgroundColor(0xFFFFFF).borderRadius(15).padding({ left: 12 })

    }.backgroundColor(0xEFEFEF).padding(20)
  }
}

效果展示:

示例2:

Blank组件的父组件未设置宽度时,min参数的使用效果。

@Entry
@Component
struct BlankExample2 {
  build() {
    Column({ space: 20 }) {
      //blank父组件不设置宽度时,Blank失效,可以通过设置min最小宽度填充固定宽度
      Row() {
        Text('Bluetooth').fontSize(18)
        Blank().color(Color.Yellow)
        Toggle({ type: ToggleType.Switch }).margin({ top: 14, bottom: 14, left: 6, right: 6 })
      }.backgroundColor(0xFFFFFF).borderRadius(15).padding({ left: 12 })

      Row() {
        Text('Bluetooth').fontSize(18)
        //设置最小宽度为160
        Blank('160').color(Color.Yellow)
        Toggle({ type: ToggleType.Switch }).margin({ top: 14, bottom: 14, left: 6, right: 6 })

      }.backgroundColor(0xFFFFFF).borderRadius(15).padding({ left: 12 })

    }.backgroundColor(0xEFEFEF).padding(20).width("100%").width("100%")
  }
}

效果展示:

Blank父组件未设置宽度时,子组件无空白填充,使用min参数设置填充尺寸。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值