我有一个 LinearProgressIndicator
,它可以正确地显示当前进度。现在我想要进度条能够动画显示,并且我认为使用 animateFloatAsState
应该非常简单。但是,不确定我哪里出错了,因为使用下面的代码,虽然显示位置正确,但进度条并没有动画效果。
@Composable
fun MyIndicator() {
val progressAnimDuration = 1500
val progressAnimation by animateFloatAsState(
targetValue = 0.35f
animationSpec = tween(durationMillis = progressAnimDuration, easing = FastOutSlowInEasing)
)
LinearProgressIndicator(
progress = progressAnimation,
...
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(20.dp)). // Rounded edges
)
}
无论何时我在屏幕上展示该组件时,我都希望进度条动画能够正确呈现。但实际情况是进度条不会进行动画,而是直接显示在正确的进度状态。
这里出了什么问题? :)
LaunchedEffect
和progress
变量的情况下实现了相同的结果。 - Douglas Fornaro