#跟着若城学鸿蒙# ArkUI组件之Blank(空白填充)
·
Blank
是一个专用于 Row
或 Column
容器中的占位组件,用来填充主轴方向上的剩余空间,使布局更加灵活、响应式。
1 定义
interface BlankInterface {
(min?: number | string): BlankAttribute;
}
- min(可选):指定
Blank
在主轴方向上的最小占用尺寸(像素或百分比)。
2 属性
declare class BlankAttribute extends CommonMethod<BlankAttribute> {
color(value: ResourceColor): BlankAttribute;
}
- color:为填充区域设置背景色,便于调试或视觉区分。
特性
- 仅在
Row
或Column
中生效;- 除
color
外,不支持其他通用样式属性;- 只有当容器存在剩余空间时,
Blank
才会占用并填满这些空间。
3 示例
@Entry @Component
struct BlankDemo {
build() {
Column({ space: 10, padding: 10 }) {
Row() {
Text('Bluetooth')
.fontSize(18)
// 占用中间剩余空间
Blank()
// 右侧开关
Toggle({ type: ToggleType.Switch })
}
.width('100%')
.height(70)
.backgroundColor(Color.Pink)
.borderRadius(15)
.padding({ left: 10 })
}
.size({ width: '100%', height: '100%' })
}
}
4 小结
Blank
可在水平或竖直布局中智能填充剩余空间,简化多端适配;- 仅支持
min
和color
两个属性; - 与
space
、justifyContent
相辅相成,共同实现响应式线性布局。
更多推荐
所有评论(0)