0

I am writing some code to override default enter and exit animations for Activity.

I am using OverridePendingTransition to achieve this task Here I am doing transition from Activity1 to Activity2.

What I want is that, Activity1 should move from right to left and Activity2 should stay appeared behind this without any animation.

How can I achieve that?

Here I have tried putting 0 for entering Animation, but it's not working.

Micho
  • 3,929
  • 13
  • 37
  • 40
Jay Vyas
  • 2,674
  • 5
  • 27
  • 58

1 Answers1

1

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" />

  • Thanks for your ans. But I want to animate exit activity only. Entering Activity should stay without any animation – Jay Vyas May 31 '17 at 10:04
  • 1
    In the above example, you can change the variation of the animation and activities behind and above. Just do hit and trail. – Muhammad Waseem May 31 '17 at 10:39