Android:TransitionManager.beginDelayedTransition为何不支持MaterialSharedAxis?
Hey, let's break down why you're hitting this issue and walk through the fixes:
1. You're probably importing the wrong TransitionManager package
There are two distinct versions of TransitionManager in Android:
- The old platform implementation:
android.transition.TransitionManager, which expects anandroid.transition.Transitionparameter - The AndroidX implementation:
androidx.transition.TransitionManager, which works withandroidx.transition.Transition
Your MaterialSharedAxis comes from com.google.android.material.transition.MaterialSharedAxis, which is built on top of the AndroidX Transition class. If you've imported the old platform TransitionManager, the IDE will flag a type mismatch because the two aren't compatible.
Fix: Double-check your imports and make sure you're using the AndroidX version:
import androidx.transition.TransitionManager
2. API mismatches in your Material Components version
You're using com.google.android.material:material:1.2.0-rc01—this is an older release candidate version, where there might have been lag between the documentation and the actual API implementation. While MaterialSharedAxis does inherit from Transition in this version, there could be hidden compatibility quirks that cause the parameter mismatch error.
Fix: Upgrade to a newer, stable version of Material Components. Versions 1.4.0 and above have better API consistency and bug fixes. Update your app-level build.gradle dependency:
implementation "com.google.android.material:material:1.4.0" // Or use the latest stable version available
Quick sanity check
Ensure you're importing the correct MaterialSharedAxis too:
import com.google.android.material.transition.MaterialSharedAxis
After making these changes, TransitionManager.beginDelayedTransition(container, sharedAxis) should compile and work as expected.
内容的提问来源于stack exchange,提问作者hamthenormal

