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:
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<changeBounds>
<targets>
<target android:targetId="@id/ivA" />
<target android:targetId="@id/ivB" />
</targets>
</changeBounds>
<changeImageTransform>
<targets>
<target android:targetId="@id/ivA" />
<target android:targetId="@id/ivB" />
</targets>
</changeImageTransform>
</transitionSet>
In the source and target ImageViews, you need to add a name tag. The name must be the same.
<ImageView
...
android:transitionName="MYTRANSITIONVIEW"
/>
In styles.xml, add to the application theme:
<item name="android:windowContentTransitions">true</item>
<item name="android:windowActivityTransitions">true</item>
<item name="android:windowSharedElementEnterTransition">@transition/my_transition</item>
<item name="android:windowSharedElementExitTransition">@transition/my_transition</item>
I am running this inside a fragment so I start the new activity like this:
Bundle bundle = null;
if (activity != null) {
ActivityOptionsCompat options =
ActivityOptionsCompat.makeSceneTransitionAnimation(activity, Frag2_, "MYTRANSITIONVIEW");
bundle = options.toBundle();
}
activity.startActivity(i, bundle);
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
supportFinishAfterTransition();
rather than finish();