android - 找到所需的转换:MaterialContainerTransform?
问题描述
在我的活动中,我正在尝试使用 MaterialContainerTransform 但它显示一个错误
找到所需的转换:MaterialContainerTransform
override fun onCreate(savedInstanceState: Bundle?) {
window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS)
setEnterSharedElementCallback(MaterialContainerTransformSharedElementCallback())
//this is giving error
window.sharedElementEnterTransition = MaterialContainerTransform().apply {
addTarget(android.R.id.content)
duration = 300L
}
window.sharedElementReturnTransition = MaterialContainerTransform().apply {
addTarget(android.R.id.content)
duration = 250L
}
我的依赖
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//material
implementation 'com.google.android.material:material:1.3.0-alpha02'
def coroutines_version = "1.3.8"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
}
解决方案
有两种使用 AndroidX 转换MaterialContainerTransform
的类型com.google.android.material.transition.MaterialContainerTransform
,包括适用于所有 API 级别的错误修复和com.google.android.material.transition。平台.MaterialContainerTransform类是建立在框架Transition 类之上的。
只有框架转换版本可用于窗口转换,因此您应确保导入正确的版本MaterialContainerTransform
:
import com.google.android.material.transition.platform.MaterialContainerTransform
推荐阅读
- php - WooCommerce 模板文件的奇怪问题 - 无法从代码中删除 DIV
- vue.js - 如何使用 Cypress 端到端快照测试来测试 Vue 单文件组件
- html - 将 CSS 类合并到一个自定义类中
- r - R:distHaversine 函数未提供预期结果
- puppeteer - 需要在目录中显示页码
- r - 在 R 中选择每列的最高值
- python - 如何找到数据集中所有点到第 k 个最近邻的距离
- php - php从输入插入mysql变量值
- javascript - 如何在 Azure 构建管道中打包 JS 应用程序并保存在单独的 C# 存储库中
- ios - 将自定义阴影添加到 TabBar 图层,同时删除阴影图像