You need to enable JavaScript to run this app. Jetpack Compose 1.0.0-rc01中AnimatedImageVector及相关方法缺失,如何替代
优惠活动
大模型
产品
解决方案
定价
更多

Jetpack Compose 1.0.0-rc01中AnimatedImageVector及相关方法缺失,如何替代

Jetpack Compose 1.0.0-rc01 AnimatedImageVector 及相关方法替代方案

从Jetpack Compose 1.0.0-beta09版本开始,原AnimatedImageVector类和animatedVectorResource方法就已从Compose基础包中移除,迁移到了独立的animation-graphics库中,1.0.0-rc01版本延续了该调整,具体替代方案如下:

1. 新增依赖引入

在模块级build.gradle文件中添加animation-graphics依赖,版本需与项目内其他Compose依赖版本保持一致:

dependencies {
    implementation "androidx.compose.animation:animation-graphics:1.0.0-rc01"
}

2. API调用替换

  • 类引用替换:原AnimatedImageVector替换为androidx.compose.animation.graphics.vector.AnimatedImageVector
  • 资源加载方法替换:原全局animatedVectorResource()方法替换为AnimatedImageVector的同名静态方法,使用逻辑无感知,示例如下:
// 加载AVD资源
val avd = AnimatedImageVector.animatedVectorResource(R.drawable.your_animated_vector_drawable)

// 配合动画状态使用示例
val isAtEnd = remember { mutableStateOf(false) }
val painter = rememberAnimatedVectorPainter(avd, isAtEnd.value)

Image(
    painter = painter,
    contentDescription = null
)

// 触发动画执行
LaunchedEffect(isAtEnd.value) {
    animateTo(targetValue = !isAtEnd.value)
}

该方案也适用于Compose 1.0.0正式版及后续所有稳定版本,无需二次调整。

内容的提问来源于stack exchange,提问作者Solvek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.12 06:12:03