I am animating a transition between activity X and activity Y.
X contains a list with images, and when an image is clicked is expanded and "zoomed" in activity Y.
So, this image is a share element between X and Y. I have set its transitionName
property in the XML layouts.
This is the code that starts activity Y:
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, clickedImage, clickedImage.getTransitionName());
startActivityForResult(intent, OPEN_PICTURE_REQUEST, options.toBundle());
Until here, everything works fine. However, I also want to animate the layout of activity Y when is entered.
To do so, I have defined the transition in a XML file (picture_enter.xml):
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
android:transitionOrdering="together">
<transition
class="android.transition.Explode"
android:startDelay="200">
<targets>
<target android:targetId="@+id/top_toolbar_container" />
</targets>
</transition>
</transitionSet>
Finally, in the onCreate
of activity Y I initalize the transition:
TransitionInflater inflater = TransitionInflater.from(this);
Transition transition = inflater.inflateTransition(R.transition.picture_enter);
Window window = getWindow();
window.setEnterTransition(transition);
But this is never performed. Only the "zoom" effect of the image works as it should. I have also tried defining the transition programmatically.
Any suggestions?
<targets>
tag is the main reason for this weird behavior. If you remove the<targets>
tag, by default transition will be applied toactivity Y
. Minor suggestion: You can directly define transitions likeexplode,
slide
etc insidetransitionSet
, thetransition
tag is mainly used to define custom transitions. – Denison