You just need to call the anim functions by moving from Activty1 to Activity2.
public class AnimUtils {
/*Right to Left Slide Animation*/
public static void rightToLeftAnimation(Activity activity) {
activity.overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
}
/*Left to Right*/
public static void leftToRightAnimation(Activity activity) {
activity.overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
}}
Create a res directory name as anim. And put the .xml files in that directory.
Here is the slide_in_right.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="500"
android:fromXDelta="100%"
android:toXDelta="0%" />
<alpha
android:duration="500"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
The slide_out_left.xml anim
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="500"
android:fromXDelta="0%"
android:toXDelta="-100%" />
<alpha
android:duration="500"
android:fromAlpha="1.0"
android:toAlpha="0.0" />
And the slide_in_left.xml
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="500"
android:fromXDelta="-100%"
android:toXDelta="0%" />
<alpha
android:duration="500"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
Also slide_out_right.xml, keep in mind you can change the animation as your choice by shifting the places of the animation in the code above.
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="500"
android:fromXDelta="0%"
android:toXDelta="100%" />
<alpha
android:duration="500"
android:fromAlpha="1.0"
android:toAlpha="0.0" />