How to delay snippet transition in Android Lollipop?

In Android Lollipop, the Activity#postponeEnterTransition() and Activity#startPostponedEnterTransition() give the Activity a delay starting from the transitions of the shared inputs and outputs until all the data has been downloaded. They are great for Activity transitions.

Is there a way to achieve the same effect when using Fragment transitions?

+16
android android-5.0-lollipop shared-element-transition activity-transition
Nov 17 '14 at 16:32
source share
1 answer

There is no direct equivalent in fragment transitions, because Fragments use FragmentTransaction, and we cannot defer what should happen in a transaction.

To get the equivalent, you can add a fragment and hide it in the transaction, and then, when the fragment is ready, delete the old fragment and show the new fragment in the transaction.

 getFragmentManager().beginTransaction() .add(R.id.container, fragment2) .hide(fragment2) .commit(); 

Later, when fragment2 is ready:

 getFragmentManager().beginTransaction() .addSharedElement(sharedElement, "name") .remove(fragment1) .show(fragment2) .commit(); 
+12
Nov 18 '14 at 0:05
source share



All Articles