新闻详情

新闻详情

首页 / 资讯中心 / 详情

HarmonyOS ArkUI Progress 进度条:5 种类型与动画演示

发布时间:2026/10/30 0:35:53来源:尧图网络
HarmonyOS ArkUI Progress 进度条:5 种类型与动画演示
系列鸿蒙 HarmonyOS 6.1 新特性实战 · 第 36 篇Progress 组件支持 5 种不同的视觉类型从线形到环形再到胶囊形配合定时器可实现丝滑的进度动画。本篇完整演示所有类型并给出通用的进度动画模式和生命周期清理最佳实践。运行效果初始状态展示 5 种进度条类型进度 0%点击“开始演示“后进度动画进行中一、Progress 5 种类型// Linear 线形最常用适合页面顶部加载进度 Progress({ value: 60, total: 100, type: ProgressType.Linear }) .width(100%).height(8) .color(#0066ff).backgroundColor(#e0e8ff) // Ring 环形适合圆形 Loading 指示 Progress({ value: 60, total: 100, type: ProgressType.Ring }) .width(80).height(80) .color(#0066ff).backgroundColor(#e0e8ff) .style({ strokeWidth: 8 }) // Eclipse 月食形视觉特殊用于特定场景 Progress({ value: 60, total: 100, type: ProgressType.Eclipse }) .width(80).height(80) .color(#8e44ad).backgroundColor(#f0e0ff) // ScaleRing 刻度环形带刻度线精密进度 Progress({ value: 60, total: 100, type: ProgressType.ScaleRing }) .width(80).height(80) .color(#e67e22).backgroundColor(#fff3e0) .style({ strokeWidth: 8, scaleCount: 20, scaleWidth: 3 }) // Capsule 胶囊形适合下载进度、文件传输 Progress({ value: 60, total: 100, type: ProgressType.Capsule }) .width(100%).height(32) .color(#27ae60).backgroundColor(#e0ffe8)二、Ring Stack 显示百分比数字环形进度条中间叠加文字是常见需求用Stack实现Stack() { Progress({ value: this.progress, total: 100, type: ProgressType.Ring }) .width(80).height(80) .color(#e74c3c).backgroundColor(#ffe0e0) .style({ strokeWidth: 8 }) Text(this.progress.toString() %) .fontSize(14).fontColor(#e74c3c).fontWeight(FontWeight.Bold) }三、进度动画setInterval aboutToDisappear进度动画核心是用setInterval定期更新State页面销毁时必须清理定时器State progress: number 0 State running: boolean false private timer: number -1 // 必须在 aboutToDisappear 清理定时器 aboutToDisappear(): void { if (this.timer 0) { clearInterval(this.timer) } } startProgress(): void { this.progress 0 this.running true this.timer setInterval(() { this.progress 2 if (this.progress 100) { this.progress 100 this.running false clearInterval(this.timer) this.timer -1 } }, 60) // 每 60ms 2%约 3 秒完成 }为什么timer初始值用 -1避免用0导致与合法 timer ID 冲突部分系统会返回 0 作为首个 timer ID用 -1 作为“未启动“哨兵值更安全。四、style 属性.style()支持的参数因类型而异// Linear / Capsule .style({ strokeWidth: 14, enableSmoothEffect: true }) // Ring .style({ strokeWidth: 8 }) // ScaleRing .style({ strokeWidth: 8, scaleCount: 20, scaleWidth: 3 })enableSmoothEffect: true开启线形进度条的平滑动效默认开启。完整代码Entry Component struct Index { State progress: number 0 State running: boolean false private timer: number -1 aboutToDisappear(): void { if (this.timer 0) { clearInterval(this.timer) } } startProgress(): void { this.progress 0 this.running true this.timer setInterval(() { this.progress 2 if (this.progress 100) { this.progress 100 this.running false clearInterval(this.timer) this.timer -1 } }, 60) } build() { Scroll() { Column({ space: 20 }) { Text(Progress 全类型进度条) .fontSize(22).fontWeight(FontWeight.Bold).fontColor(#1a1a1a) Text(当前进度 this.progress.toString() %) .fontSize(16).fontColor(#0066ff).fontWeight(FontWeight.Bold) Button(this.running ? 进行中... : 开始演示) .width(100%).height(48).backgroundColor(this.running ? #aaa : #0066ff).fontColor(#fff) .enabled(!this.running).onClick(() { this.startProgress() }) // Linear Column({ space: 8 }) { Text(一、Linear 线形).fontSize(15).fontWeight(FontWeight.Bold).fontColor(#333) Progress({ value: this.progress, total: 100, type: ProgressType.Linear }) .width(100%).height(8).color(#0066ff).backgroundColor(#e0e8ff) Progress({ value: this.progress, total: 100, type: ProgressType.Linear }) .width(100%).height(14).color(#27ae60).backgroundColor(#e0ffe8) .style({ strokeWidth: 14, enableSmoothEffect: true }) } .padding(12).backgroundColor(#fff).borderRadius(8).width(100%) .border({ width: 1, color: #e0e0e0 }).alignItems(HorizontalAlign.Start) // Ring Column({ space: 8 }) { Text(二、Ring 环形).fontSize(15).fontWeight(FontWeight.Bold).fontColor(#333) Row({ space: 24 }) { Column({ space: 4 }) { Progress({ value: this.progress, total: 100, type: ProgressType.Ring }) .width(80).height(80).color(#0066ff).backgroundColor(#e0e8ff) .style({ strokeWidth: 8 }) Text(默认).fontSize(12).fontColor(#666) } Column({ space: 4 }) { Stack() { Progress({ value: this.progress, total: 100, type: ProgressType.Ring }) .width(80).height(80).color(#e74c3c).backgroundColor(#ffe0e0) .style({ strokeWidth: 8 }) Text(this.progress.toString() %) .fontSize(14).fontColor(#e74c3c).fontWeight(FontWeight.Bold) } Text(叠加文字).fontSize(12).fontColor(#666) } } } .padding(12).backgroundColor(#fff).borderRadius(8).width(100%) .border({ width: 1, color: #e0e0e0 }).alignItems(HorizontalAlign.Start) // Eclipse ScaleRing Column({ space: 8 }) { Text(三、Eclipse 月食 / ScaleRing 刻度环).fontSize(15).fontWeight(FontWeight.Bold).fontColor(#333) Row({ space: 24 }) { Column({ space: 4 }) { Progress({ value: this.progress, total: 100, type: ProgressType.Eclipse }) .width(80).height(80).color(#8e44ad).backgroundColor(#f0e0ff) Text(Eclipse).fontSize(12).fontColor(#666) } Column({ space: 4 }) { Progress({ value: this.progress, total: 100, type: ProgressType.ScaleRing }) .width(80).height(80).color(#e67e22).backgroundColor(#fff3e0) .style({ strokeWidth: 8, scaleCount: 20, scaleWidth: 3 }) Text(ScaleRing).fontSize(12).fontColor(#666) } } } .padding(12).backgroundColor(#fff).borderRadius(8).width(100%) .border({ width: 1, color: #e0e0e0 }).alignItems(HorizontalAlign.Start) // Capsule Column({ space: 8 }) { Text(四、Capsule 胶囊形).fontSize(15).fontWeight(FontWeight.Bold).fontColor(#333) Progress({ value: this.progress, total: 100, type: ProgressType.Capsule }) .width(100%).height(32).color(#27ae60).backgroundColor(#e0ffe8) } .padding(12).backgroundColor(#fff).borderRadius(8).width(100%) .border({ width: 1, color: #e0e0e0 }).alignItems(HorizontalAlign.Start) } .padding(20).width(100%) } .width(100%).height(100%).backgroundColor(#f5f5f5) } }API 速查属性/方法说明Progress({ value, total, type })创建进度条.color(#0066ff)进度颜色.backgroundColor(#e0e8ff)轨道背景色.style({ strokeWidth, ... })样式配置按类型不同ProgressType.Linear线形ProgressType.Ring环形ProgressType.Eclipse月食形ProgressType.ScaleRing刻度环形ProgressType.Capsule胶囊形小结Linear 是最通用的加载进度、下载进度首选简洁明了Ring Stack 圆形进度用 Stack 叠加 Text 显示百分比是标准做法定时器必须在 aboutToDisappear 清理否则页面离开后定时器仍在跑浪费资源可能崩溃timer 初始值用 -1 而非 00 可能是有效 timer ID用哨兵值 -1 避免误清理上一篇Slider 与 Rating 实战 | 下一篇DatePicker / TimePicker 日期时间选择器完全指南
网站建设高端定制企业官网
RELATED

相关资讯

更多精彩内容,欢迎继续阅读

较早相关资讯

最新相关资讯

【外设】之大彩串口显示屏 2026/10/30 4:02:09

【外设】之大彩串口显示屏

大彩串口屏初步使用 1 .官网下载 STM32 屏幕 GUI 设计资料 http://www.gz-dc.com/category/typeid/4112 找到 STM32 Keil 工程,移植相关代码因项目而异进行移植,由于项目简单,本人只对用到的指令接口进行修改。 比如:注意事项&…

阅读更多 →
无法下载Windows系统iso文件 2026/10/29 23:30:48

无法下载Windows系统iso文件

当我遇到这个问题的时候,我打开了一个网站: 登录 然后我打算下载的时候: 突然那个官方的连接就可以下载了:

阅读更多 →
【清华代码熊】DeepSeek V4.1 Flash 后训练详解 2026/10/29 13:36:24

【清华代码熊】DeepSeek V4.1 Flash 后训练详解

📌 上期解析了 DeepSeek V4.1 Flash 模型架构改进,本期解析 DeepSeek V4.1 Flash 预训练/后训练技术: 🌟 预训练:45T 文本 多模态混合语料、直接训练 sparse attention(取消 DeepSeek V4 的 dense 冷启动&…

阅读更多 →
Shuffle-R1: Efficient RL framework for Multimodal Large Language Models via Data-centric Dynamic ... 2026/10/29 19:55:35

Shuffle-R1: Efficient RL framework for Multimodal Large Language Models via Data-centric Dynamic ...

文章主要内容和创新点 主要内容 本文聚焦于多模态大语言模型(MLLM)强化学习(RL)训练中的效率问题,提出了一个名为Shuffle-R1的框架。研究发现,当前RL训练存在两个关键缺陷: 优势值坍缩(Advantage Collapsing):批次中大多数优势值集中在零附近,导致有效梯度信号被淹…

阅读更多 →
PRvL: Quantifying the Capabilities and Risks of Large Language Models for PII Redaction 2026/10/29 13:36:50

PRvL: Quantifying the Capabilities and Risks of Large Language Models for PII Redaction

一、文章主要内容总结 本文聚焦于利用大型语言模型(LLMs)实现个人身份信息(PII)脱敏的研究,旨在解决传统脱敏方法(如基于规则的系统、领域特定命名实体识别(NER)模型)泛化能力差、跨格式/跨语境适应性弱的问题。 研究通过全面评估多种LLM架构(包括密集型LLM(D-LLM…

阅读更多 →
LLaVA-RE: Binary Image-Text Relevancy Evaluation with Multimodal Large Language Model 2026/10/30 5:26:05

LLaVA-RE: Binary Image-Text Relevancy Evaluation with Multimodal Large Language Model

文章主要内容和创新点 主要内容 本文聚焦于二进制图像-文本相关性评估任务(判断图像与文本“相关”或“不相关”),针对该任务中文本格式多样、相关性定义随场景变化等挑战,提出了基于多模态大语言模型(MLLM)的解决方案LLaVA-RE。 模型设计:LLaVA-RE基于LLaVA 1.5架构,…

阅读更多 →

今日资讯

本周资讯

本月资讯

看完文章仍有疑问?

联系尧图顾问,获取一对一建站咨询

立即免费咨询 📞 400-888-8888
📞 ✉