Progress({ value: this.value, total: 10, type: ProgressType.Linear })
.style({ strokeWidth: 10, enableSmoothEffect: true })
.width('80%')
.height(150)
.backgroundColor(Color.Pink)
Button('start').onClick(() => {
this.timer = setInterval((() => {
this.value += 1
}), 1000)
}) 参考以下示例,使用animation动画自定义实现进度条的更新效果:
@Entry
@Component
struct ProgressCase {
@State value: number = 0;
uiContext: UIContext | undefined = undefined;
build() {
Column() {
Column() {
Progress({ value: this.value, total: 10, type: ProgressType.Linear })
.style({ strokeWidth: 10, enableSmoothEffect: true })
.width('80%')
.height(150)
.backgroundColor(Color.Gray)
Button('start').onClick(() => {
this.uiContext = this.getUIContext();
this.uiContext?.animateTo({
duration: 10 * 1000, // 动画持续时间
curve: Curve.Linear, // 动画曲线
playMode: PlayMode.Normal, // 动画播放模式
onFinish: () => {
console.info('play end');
}
}, () => {
this.value = 10;
});
})
}.width('100%').height('100%')
}
}
}