采用Progress组件设置环形进度条,运行时存在以下问题:
问题代码示例参考如下:
@Entry @Component export struct Index { @State remainingTime: number = 0; // 剩余时间(默认10秒) aboutToAppear(): void { let timer: number timer = setInterval(() => { this.remainingTime += 1 if (this.remainingTime == 100) { clearInterval(timer) } }, 50) } build() { Column() { Stack() { // 创建垂直布局容器 Column() { Progress({ value: this.remainingTime, // 设置进度 total: 100, // 最大进度为100 type: ProgressType.Ring, // 使用环形进度条 }) .style({ strokeWidth: 20 }) .rotate({ angle: 90 }) .color('#800a59f7') .backgroundColor('#fff') .width(300) .aspectRatio(1) .animation({ duration: 10 }) } .justifyContent(FlexAlign.Center) .borderRadius(200) .backgroundColor(`rgba('10, 89, 247, 0.5')`) } .width(350) .aspectRatio(1) .borderRadius(200) .backgroundColor('#800a59f7') .alignContent(Alignment.Center) } .width('100%') .height('100%') .justifyContent(FlexAlign.Center) } }
问题效果预览:

Progress进度条组件,用于显示内容加载或操作处理等进度。Progress组件的backgroundColor属性是直接添加在Progress组件上,生效进度条的底色。如需设置整个Progress组件的背景色,需要在外层容器上设置backgroundColor,并将Progress组件嵌入到容器中。
完整示例参考如下:
@Entry @Component struct ProgressIndex { @State remainingTime: number = 100; aboutToAppear(): void { let timer: number; timer = setInterval(() => { this.remainingTime--; if (this.remainingTime === 0) { clearInterval(timer); } }, 50); } build() { Column() { Stack() { // 创建垂直布局容器 Column() { Progress({ value: this.remainingTime, // 设置进度 total: 100, // 最大进度为100 type: ProgressType.Ring, // 使用环形进度条 }) .style({ strokeWidth: 20 }) .rotate({ angle: 90 }) // 设置进度条前景色为白色 .color('#fff') // 1、问题一,将外层容器backgroundColor和Progress组件底色设置成相同且不透明的颜色 // 2、Progress组件底色设置与外层容器相同 .backgroundColor('#0a59f7') // 设置翻转 .direction(Direction.Rtl) .width(300) .aspectRatio(1) .animation({ duration: 10 }); } .justifyContent(FlexAlign.Center) .borderRadius(200); } .width(350) .aspectRatio(1) .borderRadius(200) // 问题一与问题二都需将外层容器backgroundColor修改为不透明相同颜色 .backgroundColor('#0a59f7') .alignContent(Alignment.Center); } .width('100%') .height('100%') .justifyContent(FlexAlign.Center); } }