找到所需的转换:MaterialContainerTransform?

Rah*_*war 3 android android-activity android-transitions material-design shared-element-transition

在我的活动中,我尝试使用 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
    }
Run Code Online (Sandbox Code Playgroud)

我的依赖

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'
Run Code Online (Sandbox Code Playgroud)

}

ian*_*ake 8

有两种类型MaterialContainerTransform使用com.google.android.material.transition.MaterialContainerTransform AndroidX Transition 并包含适用于所有 API 级别的错误修复和 com.google.android.material.transition platform .MaterialContainerTransform类构建于框架 Transition 类之上。

只有框架 Transition 版本可用于窗口转换,因此您应该确保导入正确的版本MaterialContainerTransform

import com.google.android.material.transition.platform.MaterialContainerTransform
Run Code Online (Sandbox Code Playgroud)