Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Google IO 2014: How to implement Activity transition with fragments?

How to implement Android 5, Lollipop, Activity Transitions using fragments?

like image 444
Ilya Gazman Avatar asked Jun 26 '14 20:06

Ilya Gazman


1 Answers

The API is pretty similar to Activity Transitions, albeit limited in some ways due to the difference between starting an activity and a fragment transaction.

Here are the basics:

  1. Use a common string when defining android:transitionName or View.setTransitionName on the views you intend to share between the fragments
  2. When creating a fragment transaction, call: FragmentTransaction.addSharedElement(View sharedElement, String name) with the view you intend to share (and its transition name).
  3. Specify the Transition that you want to be run on the fragment via: Fragment.setSharedElementEnterTransition(Transition transition)
  4. If you want to run multiple transitions, use a TransitionSet to aggregate them.
like image 74
klmprt Avatar answered Jan 01 '23 19:01

klmprt