在 OpenHarmony(ArkUI)里“进度条不显示” usually 不是组件坏了,而是使用方式或布局条件不满足。下面按最常见原因给你排查清单,基本能覆盖 90% 的情况。
Progress 默认是没有尺寸的,必须显式给宽高。
❌ 错误示例:
Progress({ value: 50, total: 100, type: ProgressType.Linear })
✅ 正确示例:
Progress({ value: 50, total: 100, type: ProgressType.Linear })
.width('80%')
.height(10)
不写
width/height,进度条直接“看不见”。
常见于:
Row / Column 没有宽高Scroll / List 里没约束尺寸示例:
Column() {
Progress({ value: 30, total: 100 })
}
如果 Column 是 0 高度,Progress 也显示不出来。
✅ 建议:
Column() {
Progress({ value: 30, total: 100 })
.width('100%')
.height(8)
}
.width('100%')
value > total → 不显示或异常total <= 0 → 不显示✅ 正确:
Progress({ value: 40, total: 100 })
ProgressType.Circular 必须有宽高,否则不显示。
Progress({ value: 60, total: 100, type: ProgressType.Circular })
.width(50)
.height(50)
比如:
可以显式设置:
Progress({ value: 50, total: 100 })
.width('80%')
.height(10)
.backgroundColor('#EEEEEE')
.color('#007DFF')
检查:
Stack 层级zIndex@Entry
@Component
struct ProgressDemo {
build() {
Column({ space: 20 }) {
Text('线性进度条')
Progress({ value: 50, total: 100, type: ProgressType.Linear })
.width('80%')
.height(10)
.color('#007DFF')
Text('环形进度条')
Progress({ value: 70, total: 100, type: ProgressType.Circular })
.width(80)
.height(80)
}
.width('100%')
.padding(20)
}
}
width / heightvalue <= total如果你愿意,可以把你的代码片段贴出来,我可以直接帮你定位是哪一条原因。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。