Animating Fragment Transactions in Android

To apply one of the default transition animations, use the setTransition method on any Fragment Transaction, passing in one of the FragmentTransaction.TRANSIT_FRAGMENT_* constants.

transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

You can also apply custom animations to Fragment Transactions by using the setCustom Animations method. This method accepts two animation XML resources: one for Fragments that are being added to the layout by this transaction, and another for Fragments being removed:

fragmentTransaction.setCustomAnimations(R.animator.slide_in_left,  R.animator.slide_out_right);

Leave a Comment