Skip to content

Instantly share code, notes, and snippets.

@KarthikKumarBA
Created November 24, 2016 10:26
Show Gist options
  • Save KarthikKumarBA/851e129c31ea4605a5cd02aa99da5aab to your computer and use it in GitHub Desktop.
Save KarthikKumarBA/851e129c31ea4605a5cd02aa99da5aab to your computer and use it in GitHub Desktop.
Activity Transition Animations -> Explode, Fade and Slide Animation
/*Create an object of activity options to enable scene transition animation*/
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this);
/*Pass it to startActivity() method as the second parameter*/
startActivity(intent, options.toBundle());
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<explode
android:duration="1000"
android:interpolator="@android:interpolator/accelerate_cubic"/>
</transitionSet>
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<fade android:duration="1000"/>
</transitionSet>
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<slide
android:duration="1000"
android:slideEdge="bottom"/>
</transitionSet>
/*Call this before setContentView() is called to enable transition*/
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
// or enable windowContentTransitions in the theme
//<item name="android:windowContentTransitions">true</item>
// Use the following code for explode animation using JAVA
Explode explodeAnimation = new Explode();
explodeAnimation.setDuration(1000);
getWindow().setEnterTransition(explodeAnimation);
// Use the following code for explode animation using XML
Transition explodeAnimation = TransitionInflater.from(this).inflateTransition(R.transition.explode);
explodeAnimation.setDuration(1000);
getWindow().setEnterTransition(explodeAnimation);
// Use the following code for slide animation using JAVA
Slide slideAnimation = new Slide();
slideAnimation.setSlideEdge(Gravity.RIGHT); // Animation is going to enter screen from right side
slideAnimation.setDuration(1000);
getWindow().setEnterTransition(slideAnimation);
// Use the following code for slide animation using XML
Transition explodeAnimation = TransitionInflater.from(this).inflateTransition(R.transition.slide);
explodeAnimation.setDuration(1000);
getWindow().setEnterTransition(explodeAnimation);
// Use the following code for fade animation using JAVA
Fade fadeAnimation = new Fade();
fadeAnimation.setDuration(1000);
getWindow().setEnterTransition(fadeAnimation);
// Use the following code for fade transition using XML
Transition explodeAnimation = TransitionInflater.from(this).inflateTransition(R.transition.fade);
explodeAnimation.setDuration(1000);
getWindow().setEnterTransition(explodeAnimation);
// If you want to enable the reserse animation after closing the activity,
// call the following method instead of finish()
finishAfterTransition();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment