Here you find examples for transition between Activities or Fragments using a shared element. An example for this behaviour is the Google Play Store App which translates an App's icon from the list to the App's details view.
In this example, one of two different ImageViews should be translated from the ChooserFragment to the DetailFragment.
In the ChooserFragment layout we need the unique transitionName attributes:
In the ChooserFragments class, we need to pass the View which was clicked and an ID to the parent Activity wich is handling the replacement of the fragments (we need the ID to know which image resource to show in the DetailFragment). How to pass information to a parent activity in detail is surely covered in another documentation.
In the DetailFragment, the ImageView of the shared element also needs the unique transitionName attribute.
In the onCreateView() method of the DetailFragment, we have to decide which image resource should be shown (if we don't do that, the shared element will disappear after the transition).
The parent Activity is receiving the callbacks and handles the replacement of the fragments.
Not to forget - the Transition itself. This example moves and scales the shared element.
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0