Monday, January 30, 2012

How to change the default transition between activities?



In android the default transition between activities is to slide from left to right.But with custom animations we can change that.First create a folder inside the res/drawable folder called “anim”.Then create a file named “fade.xml” and copy this code into it.
<?xml version="1.0" encoding="utf-8"?>

     android:interpolator="@android:anim/accelerate_interpolator"

      android:fromAlpha="0.0" android:toAlpha="1.0"

       android:duration="@android:integer/config_longAnimTime" />
create another file named “hold.xml” in the same place hold.xml.

<?xml version="1.0" encoding="utf-8"?>

<translate xmlns:android="http://schemas.android.com/apk/res/android"

       android:interpolator="@android:anim/accelerate_interpolator"

       android:fromXDelta="0" android:toXDelta="0"
 android:duration="@andro id:integer/config_longAnimTime" />
and just before starting the activity write down the following code
startActivity(new Intent(ActivityAnimation.this, SecondClass.class));
overridePendingTransition(R.anim.fade.xml,R.anim.hold.xml);

No comments:

Post a Comment