【发布时间】:2021-08-06 06:28:28
【问题描述】:
我创建了我的矢量可绘制动画,我想在 Compose 中使用。我在official documentation 中发现我需要致电animatedVectorResource。但是整个 AnimatedImageVector 已从 compose 中删除,直到下一个版本。如何在当前 compose 版本中启动动画 drawable?
【问题讨论】:
标签: android android-jetpack-compose
我创建了我的矢量可绘制动画,我想在 Compose 中使用。我在official documentation 中发现我需要致电animatedVectorResource。但是整个 AnimatedImageVector 已从 compose 中删除,直到下一个版本。如何在当前 compose 版本中启动动画 drawable?
【问题讨论】:
标签: android android-jetpack-compose
AnimatedImageVector 在1.0.0-rc01 中暂时是removed,但在最终稳定版1.0.0 中不存在。
从1.1.0-alpha01AnimatedImageVector开始,相关的API现在都在新的
androidx.compose.animation:animation-graphics 模块。
你可以使用类似的东西:
val image = animatedVectorResource(drawableId)
var atEnd by remember { mutableStateOf(false) }
Image(
painter = image.painterFor(atEnd),
contentDescription = "Your content description",
modifier = Modifier.size(64.dp).clickable {
atEnd = !atEnd
}
)
【讨论】:
您需要将 compose 更新为 1.1.0-alpha01 并添加模块 androidx.compose.animation:animation-graphics,如上一个更改日志中所示
implementation("androidx.compose.animation:animation-graphics:1.1.0-alpha01")
val image = animatedVectorResource(id = R.drawable.animated_vector)
val atEnd by remember { mutableStateOf(false) }
Icon(
painter = image.painterFor(atEnd = atEnd),
contentDescription = null
)
【讨论】: