Search code examples
androidandroid-fragmentsshared-element-transitionandroid-motionlayout

Does MotionLayout support Shared Element Transitions between fragments?


I'm considering refactoring my code to use MotionLayout for animations, but at the moment it relies heavily on shared element transitions. Is this supported by MotionLayout?

I can't seem to find any info about this online. I've found a tweet that states that MotionLayout doesn't handle Shared Element Transition between activities, but no info about fragments.


Solution

  • To answer your question as concisely as possible, yes MotionLayout does support shared elements. However, your current code will likely need some reworking to get it to happen. MotionLayout does shared element transitions by interpolating between two defined constraints for any given view. So you can definitely have a shared element interpolate between two states in a fragment transition but you will need to define the start and end in a scene file. There are some helpful examples with code for Fragment Transitions with Motion Layout at this link and a great step by step tutorial for getting started with your motion layout scene files at this link. Feel free to comment on this answer with any questions.