-
Notifications
You must be signed in to change notification settings - Fork 12
Animate Fragment transitions with custom animations
rutura edited this page Apr 16, 2017
·
1 revision
- This example works for fragments from the android support library(v4)
- The details of fragments are explained here : http://www.blikoon.com/tutorials/android-working-with-fragments
- Use it by setting a custom animation to the FragmentTransaction object as shown
FragmentTransaction transaction =
getSupportFragmentManager().beginTransaction();
//Add the animation
transaction.setCustomAnimations(R.anim.activity_open_enter,
R.anim.activity_open_exit);
//end of animation
transaction
.replace(R.id.fragment_container, fragment2);
transaction.commit();
- Tried passing the four open and close animations at once in onFragment1Message but the system just ignored.Had to explicitly set the close animations in fragment2
- We can also handle the fragment animation logic inside the fragment class itself so all transitions of its instances are animated. App1.13.3 does just that.
- !!!!!setCustomAnimations() must be called before add(), replace(), or any other action method, or the animation will not run. It is good practice to simply call this method first in the transaction block.
- Relevant files: