I am trying to animate one ImageView to another position between two activities in Android API level 21. Since "MoveImage" in Android L Preview has been removed, I use "ChangeImageTransform" instead, but the sample code in documents doesn't work out (the two images animated separately).
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<changeImageTransform>
<targets>
<target android:targetId="@id/ivA" />
<target android:targetId="@id/ivB" />
</targets>
</changeImageTransform>
</transitionSet>
Is there any working example? Thanks!
To make a screen transition animation between two activities that have a shared element, you can read this article and follow the mentioned steps:
About the 3rd step, according to the documentation:
The res/transition/your_transition.xml should be like this:
or simply like this if only ivA and ivB need to be animated:
I have got this working following this guide, a few others, and the referenced material.
A transition set in this style. I put this under res/transition:
In the source and target ImageViews, you need to add a name tag. The name must be the same.
In styles.xml, add to the application theme:
I am running this inside a fragment so I start the new activity like this:
It works on API 21 clients. It did not work on an API 16 client as the XML tags are not valid.
I hope this helps.
Slight update, to get the reverse transition on exit, I had to call
rather than finish();