Martin
Martin

Reputation: 177

How to use android.support.transition.Transition/TransitionSet as a fragment shared element enter/return transition?

Google has just released android.support.transition package which provides backport to its transition-framework, which is really awesome.

https://developer.android.com/reference/android/support/transition/package-summary.html

Unfortunately, when trying to use the Transition/TransitionSet object from this package as a shared element for fragment transaction, the application fails on following error :

E/AndroidRuntime: FATAL EXCEPTION: main
Process: gregor.martin.loginregisteractivity, PID: 26186
java.lang.ClassCastException: android.support.transition.TransitionSet cannot be cast to android.transition.Transition
 at android.support.v4.app.FragmentTransitionCompat21.wrapSharedElementTransition(FragmentTransitionCompat21.java:86)
 at android.support.v4.app.BackStackRecord.getSharedElementTransition(BackStackRecord.java:1156)
 at android.support.v4.app.BackStackRecord.configureTransitions(BackStackRecord.java:1222)
 at android.support.v4.app.BackStackRecord.beginTransition(BackStackRecord.java:1112)
 at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:721)
 at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1677)
 at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:536)
 at android.os.Handler.handleCallback(Handler.java:751)
 at android.os.Handler.dispatchMessage(Handler.java:95)
 at android.os.Looper.loop(Looper.java:154)
 at android.app.ActivityThread.main(ActivityThread.java:6077)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

Is there any way to use the new backported transition as a shared element transition?

Upvotes: 5

Views: 1458

Answers (1)

Gergely Kőrössy
Gergely Kőrössy

Reputation: 6393

UPDATE (2017-08-31)

It seems like that the support Fragment API will be able to use the support Transition API in the upcoming release of the support library (see the latest comments by Ian Lake in the same topic linked in the original answer). Whether it means that the transitions will be backported to pre-Lollipop devices or just a simple solution for the casting problems, there's no info about it, but I will update the answer once I know more. I'll try to look into the source before the release when I'll have some time.


Original answer:

This support transition API is for views only (for the time being, at least), thus you cannot use it on fragments. What a shame...

Confirmed by Ian Lake in this Google+ answer

Upvotes: 8

Related Questions