How to to animate circular progress bar with spring animation in Android Kotlin, not the normal animation

Viewed 683

I have a circular progress bar(fitness tracker) I want to animate the "progress" with spring animation using damping and stiffness. Not the normal animation.

1 Answers

You can use jetpack compose using a CircularProgressIndicator and applying a ProgressIndicatorDefaults.ProgressAnimationSpec animation.

    var progress by remember { mutableStateOf(0.0f) }
    val animatedProgress by animateFloatAsState(
        targetValue = progress,
        animationSpec = ProgressIndicatorDefaults.ProgressAnimationSpec
    )

   CircularProgressIndicator(progress = animatedProgress)

Finally assign the progress value.

Otherwise you can use a custom animationSpec like:

val customProgressAnimationSpec = SpringSpec(
    dampingRatio = 1f,
    stiffness = 50f,
    visibilityThreshold = 1 / 1000f
)

enter image description here

Related