Reputation: 3583
I am using Android X transitions to animate content with motion between two Fragments, within the same hosting Activity.
I am trying to animate an ImageView which Image is loaded with Glide and an URL.
The problem I have is, regardless of the two ImageViews sizes, their size is 0 before the image is loaded, and because of that, the transitions capture wrong layout values and therefore show a shrinking animation (animating to size 0).
I have read about using postponeEnterTransition()
which should, in association with startPostponedEnterTransition()
delay the transition for the duration between the two calls.
This is the schema:
On Fragment A's image click, the Fragment B is loaded.
In Fragment B's onCreate
I set my transitions using setSharedElementEnterTransition(transitions)
. Then I immediately call postponeEnterTransition()
;
In Fragment B's onCreateView
, I await for the ImageView to be pre-drawn (using the ViewTreeObserver), after layout inflation, and then I call startPostponedEnterTransition()
.
Using a breakpoint and a listener on my transitions, the listener#onTransitionStarted is triggered before I reach the pre-draw callback, which proves the transition captured wrong layout values.
Also, another proof that postponeEnterTransition()
has no effect whatsoever, removing the call to startPostponedEnterTransition()
does not hold the transition forever.
What am I doing wrong ? And of course, when returning to Fragment A, the same shrinking animation is being played out as well...
Upvotes: 1
Views: 4760
Reputation: 597
You should set reordering allowed during your fragment transaction by adding setReorderingAllowed(true)
to your transaction.
See Android docs and the Reordering part of this blog post by Chris Banes for more context.
Upvotes: 4