如何在 Compose 中使用动画矢量绘图

Hit*_*ene 5 android android-image android-drawable android-vectordrawable android-jetpack-compose

我创建了矢量可绘制动画,并且想在 Compose 中使用。我在官方文档中发现我需要调用animatedVectorResource. 但AnimatedImageVector在下一个版本之前,整个内容已从 compose 中删除。如何在当前的 compose 版本中启动动画绘图?

Ste*_*one 4

您需要更新 compose并添加上次更改日志中所示的1.1.0-alpha01模块androidx.compose.animation:animation-graphics

在此输入图像描述

implementation("androidx.compose.animation:animation-graphics:1.1.0-alpha01")
Run Code Online (Sandbox Code Playgroud)
val image = animatedVectorResource(id = R.drawable.animated_vector)
val atEnd by remember { mutableStateOf(false) }
Icon(
   painter = image.painterFor(atEnd = atEnd),
   contentDescription = null
)
Run Code Online (Sandbox Code Playgroud)