圆环进度条参考官方文档中的进度条 ,虚线通过Divider()组件设置属性,旋转角度跟随进度条进度。
@Entry @Component struct Index { @State rotateAngle: number = 0; uiContext: UIContext | undefined = undefined; aboutToAppear() { this.uiContext = this.getUIContext(); if (!this.uiContext) { console.warn('no uiContext'); return; } } build() { Column() { Column() { Progress({ value: 20, total: 150, type: ProgressType.ScaleRing }).width(100).height(100) .backgroundColor(Color.Black) .style({ scaleCount: 20, scaleWidth: 5 }) Divider() .height(40) .width(0) .borderWidth(2) .margin({ top: -90 }) // 通过centerX、centerY设置旋转中心 .rotate({ centerX: '100%', centerY: '100%', angle: this.rotateAngle }) .onAppear(() => { this.uiContext?.animateTo({ duration: 3000, curve: Curve.Linear, iterations: -1, // 设置-1表示动画无限循环 }, () => { this.rotateAngle = 360 * 20 / 150; }); }) } .width('100%') .height('100%') .justifyContent(FlexAlign.Center) .alignItems(HorizontalAlign.Center) } } }