Meh*_*ncb 1 android kotlin android-jetpack android-jetpack-compose
我需要你的帮助。
一切都在标题中,我不知道我该怎么做......请帮助我。我使用了很多东西,如补间、枚举类等,但没有用,我想要 200dp 的初始值,当活动打开时,2 秒后,图像在 2 秒内从 200dp 变为 100dp。谢谢。
@Gabrial 的答案是完美的,但可以通过使用图形层属性而不是大小来优化,这将导致更好的性能,因为在动画期间不会发生重组。
编辑。无意冒犯 @Gabrial。你的 anser 仍然会触发重组,因为你没有使用带有 lambda 修饰符的图形层。
根据文档,如果图层参数由 androidx.compose.runtime.State 支持或动画值更喜欢在 GraphicsLayerScope 上使用 lambda 块进行重载,因为读取块内的状态只会导致图层属性更新,而不会触发重组和重新布局。
所以上面的代码片段应该是这样的
val animatedProgress = remember { Animatable(1f) }
LaunchedEffect(animatedProgress) {
animatedProgress.animateTo(0.5f,
animationSpec = tween(
durationMillis = 2000,
delayMillis = 2000
))
}
Image(
painterResource(id = R.drawable.xxx), "contentDescription",
modifier = Modifier
.size(100.dp)
.graphicsLayer{
scaleY = animatedProgress.value,
scaleX = animatedProgress.value
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2330 次 |
| 最近记录: |