material-components-android: [Motion] Can't use both Container transition and Shared element
Description: I’m trying to implement transition #1, which is from the new material motion system.
If I use sharedElementEnterTransition = MaterialContainerTransform() then I get a really nice looking container transform, BUT my issue is that my container has an image and I’d like to share that image. There doesn’t seem to be clear guidance on how to do this, so I tried my best with just getting the container (outer viewgroup) and the contained imageView, and it doesn’t seem to work. I can verify that my shared element is working, because if I remove my container transition and just put the transition on the image view via TransitionInflater.from(context).inflateTransition(android.R.transition.move) then I get a nice animated shared element. My issue is that I want both.
Looking at the gif from the material team below, it does seem like they include a package deal of a container transition + a shared element imageview.
https://miro.medium.com/max/1400/1*0vL7z6wwb1X9tvR6_rdQLw.gif

Expected behavior: As far as I can understand, MaterialContainerTransform() should allow you to chain another shared element.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 26 (11 by maintainers)
Have spent ages trying to figure out why my container transform wasn’t scaling and this was the issue! Thanks for this.
Thanks @ColtonIdle! Let’s file separate issues for anything specific that is happening.
@dsn5ft sounds good. I will still give this a whirl when I get a chance to try the newest updates. Thanks again!
Yep exactly, that’s what I was thinking with the FrameLayout.
Thanks for all of the info!
I would definitely recommend a container transform (without traditional shared element) for that Kodaline transition. It wouldn’t result in the exact same staggered effect as in the GIF, but when set up correctly (with the correct container colors in place), I think it would look really good. And you could probably still have some of that staggered polish effect by having the fab be GONE initially and then fading/scaling it in, potentially even while the container transform animation is happening.
Re: the “bad” container transform, I think that’s a relatively common issue we’re seeing when the incoming screen/view doesn’t have a background, but it should be easily fixable. I’d suggest either:
android:background="?attr/colorSurface") on your root view in the incoming screen, that way you don’t get any overlap due to transparency.OR
(I actually did the latter in a recent update to our Catalog app - https://github.com/material-components/material-components-android/commit/d5faac589b283dbe90b45952cd41bdf5cc2f63a6)