鸿蒙HarmonyOS实战-ArkUI组件(Progress)_鸿蒙自定义progress,2024年最新2024年五面蚂蚁

45 阅读4分钟

在这里插入图片描述

2.设置进度条样式

组件名称Progress
可选类型5种:ProgressType.Linear、ProgressType.Ring、ProgressType.ScaleRing、ProgressType.Eclipse、ProgressType.Capsule
设置方式在创建时通过设置ProgressType枚举类型给type可选项指定Progress类型
样式概述
ProgressType.Linear线性样式
ProgressType.Ring环形无刻度样式
ProgressType.ScaleRing环形有刻度样式
ProgressType.Eclipse圆形样式
ProgressType.Capsule胶囊样式

🦋2.1 线性样式

@Entry @Component struct Index { build() { Column() { Progress({ value: 20, total: 100, type: ProgressType.Linear }).width(200).height(50) Progress({ value: 20, total: 100, type: ProgressType.Linear }).width(50).height(200) } .padding(10) .backgroundColor(0xDCDCDC) .width('100%') .height('100%') } }

在这里插入图片描述

🦋2.2 环形无刻度样式

@Entry @Component struct Index { build() { Column() { // 从左往右,1号环形进度条,默认前景色为蓝色,默认strokeWidth进度条宽度为2.0vp Progress({ value: 40, total: 150, type: ProgressType.Ring }).width(100).height(100) // 从左往右,2号环形进度条 Progress({ value: 40, total: 150, type: ProgressType.Ring }).width(100).height(100) .color(Color.Grey) // 进度条前景色为灰色 .style({ strokeWidth: 15}) // 设置strokeWidth进度条宽度为15.0vp } .padding(10) .backgroundColor(0xDCDCDC) .width('100%') .height('100%') } }

在这里插入图片描述

🦋2.3 环形有刻度样式

@Entry @Component struct Index { build() { Column() { Progress({ value: 20, total: 150, type: ProgressType.ScaleRing }).width(100).height(100) .backgroundColor(Color.Black) .style({ scaleCount: 20, scaleWidth: 5 }) // 设置环形有刻度进度条总刻度数为20,刻度宽度为5vp 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 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 } .padding(10) .backgroundColor(0xDCDCDC) .width('100%') .height('100%') } }

在这里插入图片描述

🦋2.4 圆形样式

@Entry @Component struct Index { build() { Column() { // 从左往右,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) } .padding(10) .backgroundColor(0xDCDCDC) .width('100%') .height('100%') } }

在这里插入图片描述

🦋2.5 胶囊样式

@Entry @Component struct Index { build() { Column() { Progress({ value: 10, total: 150, type: ProgressType.Capsule }).width(100).height(50) Progress({ value: 20, total: 150, type: ProgressType.Capsule }).width(50).height(100).color(Color.Grey) Progress({ value: 50, total: 150, type: ProgressType.Capsule }).width(50).height(100).backgroundColor(Color.Black) } .padding(10) .backgroundColor(0xDCDCDC) .width('100%') .height('100%') } }

在这里插入图片描述

3.案例

Progress组件通常用于展示某个任务或者进程的进度,可以向用户传达当前操作的进展情况。以下是Progress组件的一些实际应用场景:

  1. 文件上传或下载的进度条展示
  2. 音视频播放器中的播放进度条
  3. 游戏中的加载进度条
  4. 网页加载进度条
  5. 软件安装或更新的进度条展示
  6. 数据库操作的进度条展示
  7. 任务管理系统中的进度展示
  8. 项目管理系统中的任务进度展示

Progress组件可以直观地展示某个任务的完成情况,帮助用户了解任务的进度及剩余时间,提高用户体验和操作效率。

案例:

@Entry @Component struct Index { @State progressValue: number = 0 // 设置进度条初始值为0 build() { Column() { Column() { Progress({value:0, total:100, type:ProgressType.Capsule}).width(200).height(50) .style({strokeWidth:50}).value(this.progressValue) Row().width('100%').height(5) Button("进度条+5") .onClick(()=>{ this.progressValue += 5 if (this.progressValue > 100){ this.progressValue = 0

img img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!