3.4、HarmonyOS Next 进度条(Progress)

Progress 是进度条显示组件,显示内容通常为某次目标操作的当前进度。具体用法请参考

创建进度条

Progress 通过调用接口来创建,接口调用形式如下

ts 复制代码
Progress(options: {value: number, total?: number, type?: ProgressType})

该接口用于创建 type 样式的进度条,其中 value 用于设置初始进度值,total 用于设置进度总长度,type 决定 Progress 样式。

ts 复制代码
Progress({ value: 24, total: 100, type: ProgressType.Linear }) // 创建一个进度总长为100,初始进度值为24的线性进度条

设置进度条样式

Progress 有5种可选类型,在创建时通过设置 ProgressType 枚举类型给type可选项指定 Progress 类型。其分别为:ProgressType.Linear(线性样式)、 ProgressType.Ring(环形无刻度样式)、ProgressType.ScaleRing(环形有刻度样式)、ProgressType.Eclipse(圆形样式)和ProgressType.Capsule(胶囊样式)。

  • 线性样式进度条(默认类型)
ts 复制代码
Row() {
    Progress({ value: 20, total: 100, type: ProgressType.Linear }).width(200).height(50).margin({left: 10})
    Progress({ value: 20, total: 100, type: ProgressType.Linear }).width(50).height(200).margin({left: 10})
  }
  • 环形无刻度样式进度条
ts 复制代码
Row() {
   // 从左往右,1号环形进度条,默认前景色为蓝色,默认strokeWidth进度条宽度为2.0vp
   Progress({ value: 40, total: 150, type: ProgressType.Ring }).width(100).height(100).margin({left: 10, top: 10})
   // 从左往右,2号环形进度条
   Progress({ value: 40, total: 150, type: ProgressType.Ring }).width(100).height(100)
     .color(Color.Grey)    // 进度条前景色为灰色
     .style({ strokeWidth: 15})    // 设置strokeWidth进度条宽度为15.0vp
     .margin({left: 10, top: 10})
}
  • 环形有刻度样式进度条
ts 复制代码
Row() {
   Progress({ value: 20, total: 150, type: ProgressType.ScaleRing }).width(100).height(100)
     .backgroundColor(Color.Black)
     .style({ scaleCount: 20, scaleWidth: 5 })    // 设置环形有刻度进度条总刻度数为20,刻度宽度为5vp
     .margin({left: 10, top: 10})
   Progress({ value: 20, total: 150, type: ProgressType.ScaleRing }).width(100).height(100)
     .backgroundColor(Color.Black)
     .style({ strokeWidth: 15, scaleCount: 20, scaleWidth: 5 })    // 设置环形有刻度进度条宽度15,总刻度数为20,刻度宽度为5vp
     .margin({left: 10, top: 10})
   Progress({ value: 20, total: 150, type: ProgressType.ScaleRing }).width(100).height(100)
     .backgroundColor(Color.Black)
     .style({ strokeWidth: 15, scaleCount: 20, scaleWidth: 3 })    // 设置环形有刻度进度条宽度15,总刻度数为20,刻度宽度为3vp
     .margin({left: 10, top: 10})
 }
  • 圆形样式进度条
ts 复制代码
// 从左往右,1号圆形进度条,默认前景色为蓝色
Progress({ value: 10, total: 150, type: ProgressType.Eclipse }).width(100).height(100)
// 从左往右,2号圆形进度条,指定前景色为灰色
Progress({ value: 20, total: 150, type: ProgressType.Eclipse }).color(Color.Grey).width(100).height(100)
  • 胶囊样式进度条
ts 复制代码
 Row() {
     Progress({ value: 10, total: 150, type: ProgressType.Capsule }).width(100).height(50).margin({left: 10, top: 10})
     Progress({ value: 20, total: 150, type: ProgressType.Capsule }).width(50).height(100).color(Color.Grey).margin({left: 10, top: 10})
     Progress({ value: 50, total: 150, type: ProgressType.Capsule }).width(50).height(100).backgroundColor(Color.Black).margin({left: 10, top: 10})
}

上一篇 3.3、切换按钮(Toggle) 下一篇 3.5、文本显示(Text/Span)

相关推荐
钉先生贾14 小时前
HarmonyOS 7.0 多设备协同实战 35:用户撤销分享链接后,怎样使缓存入口同时失效
缓存·华为·harmonyos
陈橘又青1 天前
把加密 DNS 关进本地 5353:dnscrypt-proxy 的鸿蒙 PC 复刻笔记
华为·harmonyos
kirk_wang1 天前
HarmonyOS 7.0 A2A多轮实战:缺少健康摘要授权时如何安全暂停
华为·harmonyos
JosieBook1 天前
【鸿蒙开源】把 Windows 任务栏上的流量表搬到鸿蒙 PC:TrafficMonitor 1.86 的 C++ 内核移植实践
c++·windows·harmonyos
网易云信1 天前
聊天图片能“按意思搜”了:云信 NIM 鸿蒙 SDK 的两项升级
harmonyos
HarmonyOS_SDK1 天前
【HarmonyOS API 26】端云通信加速,助力京东打造稳定流畅的购物直播体验
harmonyos
kirk_wang2 天前
HarmonyOS 7.0 A2A任务链实战:用getRelatedTasks核对随访材料来源
华为·harmonyos
OH_TPC2 天前
lottie-turbo 源码解读(一):lottie_bridge 与 Animator——声明式配置到 native 渲染的桥接
harmonyos
钉先生贾2 天前
HarmonyOS 7.0 空间计算实战 30:退出沉浸视图后,怎样清理临时资源并恢复上下文
华为·harmonyos·空间计算
钉先生贾2 天前
HarmonyOS 7.0 空间计算实战 28:空间内容加载失败时,怎样提供可完成的二维替代
华为·harmonyos·空间计算