微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

找到所需的转换:MaterialContainerTransform?

如何解决找到所需的转换: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'

}

解决方法

有两种类型的MaterialContainerTransformcom.google.android.material.transition.MaterialContainerTransform 使用AndroidX Transition,其中包括适用于所有API级别的错误修复程序,以及基于框架Transition类构建的com.google.android.material.transition.platform.MaterialContainerTransform类。

仅框架过渡版本可用于窗口过渡,因此您应确保导入的MaterialContainerTransform版本正确:

import com.google.android.material.transition.platform.MaterialContainerTransform

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。