发布时间:2026/7/18 22:35:07
HarmonyOS ArkUI Marquee 跑马灯与 Gauge 仪表盘:公告滚动与数据展示 系列鸿蒙 HarmonyOS 6.1 新特性实战 · 第 43 篇Marquee 实现水平滚动文字效果常用于新闻公告条、优惠信息滚动展示Gauge 是半圆或弓形仪表盘组件适合可视化速度、电量、得分等数值。本篇将两者结合搭建一个带播控按钮的公告条与实时数据仪表盘示例页面覆盖颜色分段、中心文字叠加等进阶用法。运行效果初始状态Marquee 停止 Gauge 显示默认值Marquee 滚动中 点击按钮更新 Gauge 数值Marquee 跑马灯Marquee 通过start属性控制滚动状态step控制每帧移动像素数loop控制循环次数。State marqueeStart: boolean false State marqueeStep: number 8 Marquee({ start: this.marqueeStart, step: this.marqueeStep, loop: -1, fromStart: true, src: HarmonyOS 6.1 正式发布新增 Marquee、Gauge、Search 等多个 ArkUI 组件欢迎体验 }) .fontSize(14) .fontColor(#333333) .layoutWeight(1) .height(36)参数说明start: false初始暂停start: true立即开始滚动step每帧移动像素数6-10 为舒适速度超过 15 会感觉很快loop: -1无限循环loop: 0播放一次后停止fromStart: true每次循环从头开始false则接续当前位置将 Marquee 嵌入公告条容器Row({ space: 8 }) { Text(公告).fontSize(12).fontColor(#ff6600) .padding({ left: 6, right: 6, top: 3, bottom: 3 }) .backgroundColor(#fff3e0) .borderRadius(4) Marquee({ start: this.marqueeStart, step: this.marqueeStep, loop: -1, fromStart: true, src: this.marqueeText }) .fontSize(14).fontColor(#333333).layoutWeight(1).height(36) Image(this.marqueeStart ? $r(app.media.pause) : $r(app.media.play)) .width(20).height(20) .onClick(() { this.marqueeStart !this.marqueeStart }) } .width(100%) .padding({ left: 12, right: 12 }) .height(44) .backgroundColor(#fffbf0) .borderRadius(8)Gauge 仪表盘Gauge 以弓形刻度盘展示数值startAngle和endAngle以时钟方向定义弧度范围0 12点90 3点180 6点270 9点。State gaugeVal: number 65 Gauge({ value: this.gaugeVal, min: 0, max: 100 }) .startAngle(210) .endAngle(150) .strokeWidth(18) .description(null) .width(200) .height(200)startAngle(210)对应左下方约 7 点位endAngle(150)对应右下方约 5 点位两者组合形成经典的 270° 弓形仪表盘。Gauge 颜色分段通过.colors()传入颜色区间数组实现红/黄/绿三段渐变直观表达数值健康程度Gauge({ value: this.gaugeVal, min: 0, max: 100 }) .colors([ [Color.Red, 0.3], [Color.Yellow, 0.4], [Color.Green, 0.3] ]) .startAngle(210) .endAngle(150) .strokeWidth(18) .description(null) .width(200) .height(200)每个元素为[颜色, 占比]占比之和应为 1.0对应刻度盘从起点到终点的比例分配。Stack 叠加中心文字使用Stack将文字叠加在 Gauge 中心实现数值直读效果Stack() { Gauge({ value: this.gaugeVal, min: 0, max: 100 }) .colors([ [Color.Red, 0.3], [Color.Yellow, 0.4], [Color.Green, 0.3] ]) .startAngle(210) .endAngle(150) .strokeWidth(18) .description(null) .width(200) .height(200) Column({ space: 2 }) { Text(${this.gaugeVal}) .fontSize(36) .fontWeight(FontWeight.Bold) .fontColor(this.getValueColor()) Text(分).fontSize(13).fontColor(#999999) } .offset({ y: 16 }) } .width(200) .height(200)颜色动态映射getValueColor(): string { if (this.gaugeVal 30) return #e74c3c if (this.gaugeVal 70) return #f39c12 return #27ae60 }完整代码Entry Component struct MarqueeGaugePage { State marqueeStart: boolean false State marqueeStep: number 8 State marqueeText: string HarmonyOS 6.1 正式发布新增 Marquee、Gauge、Search 等多个 ArkUI 组件欢迎体验新特性 State gaugeVal: number 65 State speedLabel: string 良好 getValueColor(): string { if (this.gaugeVal 30) return #e74c3c if (this.gaugeVal 70) return #f39c12 return #27ae60 } updateGauge(delta: number): void { const next this.gaugeVal delta this.gaugeVal Math.max(0, Math.min(100, next)) if (this.gaugeVal 30) { this.speedLabel 危险 } else if (this.gaugeVal 70) { this.speedLabel 一般 } else { this.speedLabel 良好 } } build() { Column({ space: 20 }) { Text(公告栏 仪表盘).fontSize(18).fontWeight(FontWeight.Bold).fontColor(#333333) .width(100%).padding({ left: 16 }) // 公告条 Row({ space: 8 }) { Text(公告) .fontSize(12).fontColor(#ff6600) .padding({ left: 6, right: 6, top: 3, bottom: 3 }) .backgroundColor(#fff3e0).borderRadius(4) Marquee({ start: this.marqueeStart, step: this.marqueeStep, loop: -1, fromStart: true, src: this.marqueeText }) .fontSize(14).fontColor(#333333).layoutWeight(1).height(36) Text(this.marqueeStart ? ⏸ : ▶) .fontSize(18) .onClick(() { this.marqueeStart !this.marqueeStart }) } .width(100%) .padding({ left: 12, right: 12 }) .height(44) .backgroundColor(#fffbf0) .borderRadius(8) .margin({ left: 16, right: 16 }) // 速度调节 Row({ space: 12 }) { Text(滚动速度).fontSize(13).fontColor(#666666) ForEach([4, 8, 16], (step: number) { Text(${step 4 ? 慢 : step 8 ? 中 : 快}) .fontSize(13) .fontColor(this.marqueeStep step ? #ffffff : #0066ff) .padding({ left: 14, right: 14, top: 6, bottom: 6 }) .backgroundColor(this.marqueeStep step ? #0066ff : #e8f0ff) .borderRadius(16) .onClick(() { this.marqueeStep step }) }) } .padding({ left: 16, right: 16 }) Divider().strokeWidth(1).color(#eeeeee).margin({ left: 16, right: 16 }) // 仪表盘 Text(实时评分).fontSize(15).fontWeight(FontWeight.Medium).fontColor(#333333) .width(100%).padding({ left: 16 }) Stack() { Gauge({ value: this.gaugeVal, min: 0, max: 100 }) .colors([ [Color.Red, 0.3], [Color.Yellow, 0.4], [Color.Green, 0.3] ]) .startAngle(210) .endAngle(150) .strokeWidth(18) .description(null) .width(220) .height(220) Column({ space: 2 }) { Text(${this.gaugeVal}) .fontSize(40) .fontWeight(FontWeight.Bold) .fontColor(this.getValueColor()) Text(this.speedLabel) .fontSize(14) .fontColor(this.getValueColor()) } .offset({ y: 20 }) } .width(220) .height(220) // 控制按钮 Row({ space: 16 }) { Button(-10).width(72).onClick(() { this.updateGauge(-10) }) Button(-1).width(60).onClick(() { this.updateGauge(-1) }) Button(1).width(60).onClick(() { this.updateGauge(1) }) Button(10).width(72).onClick(() { this.updateGauge(10) }) } } .width(100%) .height(100%) .backgroundColor(#f8f8f8) .padding({ top: 20, bottom: 20 }) } }API 速查属性/方法说明Marquee({ start, step, loop, fromStart, src })创建滚动文字src 为文字内容starttrue 滚动false 暂停step每帧移动像素数推荐 6-10loop循环次数-1 无限0 播放一次fromStarttrue 每次从头播放Gauge({ value, min, max })创建仪表盘value 为当前值.startAngle(deg)弧度起始角时钟方向012点.endAngle(deg)弧度终止角.strokeWidth(px)刻度盘弧线粗细.colors([[color, ratio], ...])颜色分段数组ratio 之和为 1.0.description(null)传 null 隐藏默认描述文字小结Marquee 的start属性绑定State变量修改即可在运行时控制播放/暂停step值越大滚动越快6-10 在大多数屏幕密度下视觉舒适超过 15 会显得跳跃Gauge 角度遵循时钟方向startAngle(210)endAngle(150)组合出 270° 弓形颜色分段数组中各ratio之和必须等于 1.0否则仪表盘颜色显示异常使用Stack Column offset叠加中心文字无需绝对定位适配不同屏幕尺寸description(null)可隐藏 Gauge 默认描述区域腾出空间给自定义内容上一篇QRCode 与 PatternLock 安全组件 | 下一篇Menu 与 ContextMenu 长按菜单全配置

相关新闻

2026/7/18 22:35:07

HarmonyOS ArkUI QRCode 与 PatternLock:二维码生成与手势密码

系列:鸿蒙 HarmonyOS 6.1 新特性实战 第 42 篇 QRCode 和 PatternLock 是 ArkUI 面向安全与分享场景的两个专用组件。QRCode 可将任意字符串实时渲染为二维码图像,PatternLock 则提供九宫格手势密码交互,常用于应用锁、支付验证等场景。本篇…

2026/7/18 22:30:07

帝国CMS自定义字段扩展技巧

做网站最怕功能受限,想加个多图展示、自定义列表,原来的字段不够用还改不了?不少站长搭建资讯站、图片站、招聘站这类功能站点时,都会卡在字段扩展这一步,其实用帝国CMS就能轻松解决,只是很多人没摸对新增修…

2026/7/18 22:30:07

90克“小马达”,给心脏“续命”——人工心脏到底靠不靠谱?

慢性心衰就像心脏这个“水泵”慢慢磨损了,泵血越来越吃力。吃药能缓解,但有些患者病情持续恶化,到了终末期,连走路、吃饭都喘得厉害。这时候,除了等心脏移植(但我国每年仅约700例,而心衰患者超过…

2026/7/19 0:20:17

Kubernetes Local PV:推理服务用本地 NVMe 做模型缓存

Kubernetes Local PV:推理服务用本地 NVMe 做模型缓存基础设施不需要漂亮话。模型加载的瓶颈不在 GPU,而在存储——一个 70B 参数的模型从网络存储拉到显存的时间,够让 GPU 空转 30 秒。一、模型加载:比推理本身更慢的环节 在线推…

2026/7/19 0:20:17

【单片机毕业设计】基于 51 单片机的多环境参数智能监测与自动调控系统设计,基于 STM32 的温室温湿度烟雾光照一体化智能控制装置开发(017902)

文章目录20 个相关毕业设计备选题目项目研究背景摘要总体方案核心功能一、基础采集功能二、人机交互模式切换核心功能三、自动闭环调控核心功能四、辅助稳定运行功能技术路线项目演示关于我们项目案例源码获取博主介绍:✌️码农一枚 ,专注于大学生项目实…

2026/7/19 0:20:17

题解生成的流式输出优化:首字延迟与生成速度的博弈

题解生成的流式输出优化:首字延迟与生成速度的博弈 一、用户盯着空白页等 10 秒,和看着文字逐字冒出来等 15 秒,哪个体验更好 直觉上,10 秒比 15 秒短,应该是 10 秒的方案更好。但实际用户感知恰恰相反:看空…

2026/7/19 0:20:17

千万别让AI同时测登录和支付——我们公司的服务器宕机了一整天

一个真实的“AI压测翻车”复盘,血的教训换来的8条铁律 2026年7月16日,上午10:23。 我盯着Grafana面板上那条直线往下砸的CPU曲线,手里的美式咖啡差点洒在键盘上。 “所有服务全部超时,登录和支付模块同时挂了。” 运维老张在群里艾…

2026/7/19 0:20:17

一个文件夹 + 一个Markdown文件 = 你的第一个Skill

上个月,我被临时抽调去支援一个“代码抢救”项目——一个迭代了四年的支付模块,文档约等于零,单元测试覆盖率不到 20%,原班人马跑得就剩一个刚转正的哥们儿。leader 让我带着他把核心接口的单元测试补齐,我一打开那个 …

2026/7/19 0:15:17

【JVM调优实战】03-三大主流JVM实现横评

三大主流 JVM 实现横评:HotSpot、OpenJ9、GraalVM 怎么选 本文是《JVM调优实战》专栏第 3 讲。 引言 大多数 Java 开发者日常接触的 JVM 只有一个——HotSpot,它是 Oracle JDK 和 OpenJDK 的默认实现,也是绝大多数生产环境的标配。但 HotSpot 并不是唯一的选择,也不是所有…

2026/7/19 0:00:15

Unity与Python本地通信:基于Flask的跨语言数据交换实战

1. 项目概述:为什么我们需要一个本地通信服务器?在游戏开发、数字孪生、仿真训练等众多领域,Unity作为强大的实时3D内容创作平台,其核心逻辑通常由C#驱动。然而,当我们需要进行复杂的数据分析、机器学习推理、科学计算…

2026/7/19 0:00:15

Unity与Python本地通信:基于Flask的跨语言数据交换实战

1. 项目概述:为什么我们需要一个本地通信服务器?在游戏开发、数字孪生、仿真训练等众多领域,Unity作为强大的实时3D内容创作平台,其核心逻辑通常由C#驱动。然而,当我们需要进行复杂的数据分析、机器学习推理、科学计算…

2026/7/18 16:50:29

3个高效策略:快速掌握Axure中文界面配置

3个高效策略:快速掌握Axure中文界面配置 【免费下载链接】axure-cn Chinese language file for Axure RP. Axure RP 简体中文语言包。支持 Axure 11、10、9。不定期更新。 项目地址: https://gitcode.com/gh_mirrors/ax/axure-cn 还在为Axure RP的英文界面感…