| Shared Element Transition between two Fragments 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. Syntax - transaction.addSharedElement(sharedElementView, "targetTransitionName");
- fragment.setSharedElementEnterTransition(new CustomTransaction());
|