为何在Jetpack Compose中无法使用Modifier.sharedBounds?
确认依赖坐标正确性
你使用的libs.androidx.animation需要对应正确的Compose动画依赖,在项目的libs.versions.toml文件中,需确保配置为:[versions] composeAnimation = "1.7.0-rc01" [libraries] androidx-animation = { module = "androidx.compose.animation:animation", version.ref = "composeAnimation" }若libs配置未正确指向该坐标,会导致依赖未被正确引入。
检查导入语句
在使用sharedBounds的Compose代码文件顶部,必须添加以下导入:import androidx.compose.animation.sharedBounds import androidx.compose.animation.rememberSharedContentState缺少导入会直接触发未解析引用错误。
同步依赖并清理缓存
- 点击Android Studio顶部的「Sync Project with Gradle Files」按钮同步项目依赖
- 执行「File → Invalidate Caches... → Invalidate and Restart」清理IDE缓存,避免缓存导致的API识别异常
另外需注意:sharedBounds是Compose 1.7.0及以上版本新增的API,你指定的1.7.0-rc01版本已支持该功能,但要保证项目中Compose BOM的版本与动画依赖版本一致,否则可能出现版本兼容性问题。
内容的提问来源于stack exchange,提问作者zmt
相关产品推荐
相关产品推荐

