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

房东的猫 提交于 2019-12-12 11:04:52

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/39016278/how-to-use-android-support-transition-transition-transitionset-as-a-fragment-sha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!