【问题标题】:How to to animate circular progress bar with spring animation in Android Kotlin, not the normal animation如何在Android Kotlin中使用弹簧动画制作圆形进度条,而不是普通动画
【发布时间】:2021-10-12 03:56:49
【问题描述】:

我有一个圆形进度条(健身追踪器)我想使用阻尼和刚度为“progress”设置动画。 不是正常的动画。

【问题讨论】:

    标签: android kotlin android-progressbar android-jetpack-compose material-components-android


    【解决方案1】:

    您可以使用 CircularProgressIndicator 并应用 ProgressIndicatorDefaults.ProgressAnimationSpec 动画来使用 jetpack compose。

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

    最后分配progress 值。

    否则您可以使用自定义animationSpec,例如:

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

    【讨论】:

    • 目前我们没有在我们的项目中使用jetpack我可以在没有jetpack的情况下实现这个吗?在进度的最终位置,它应该显示弹簧行为。
    猜你喜欢
    • 2018-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多