37

What I'm trying to achieve is to override the start activity animation.

The animation should give the impression that the old activity is on top of the new activity, and then slides down and out of the screen to reveal the new activity. I've tried multiple ways such as using overridePendingTransition(startAnim, exitAnim) But the problem is they both animate in the same timeline. So overridePendingTransition(R.anim.hold, R.anim.exit_slide_down); You never see the exit animation because the new activity is on top. Can this be achieved using the framework?

enter image description here

Graham Borland
  • 60,055
  • 21
  • 138
  • 179
johncc
  • 918
  • 1
  • 8
  • 13
  • I believe you can delay an animation, sorry for not being to more help though. – Warpzit Feb 15 '12 at 13:45
  • possible duplicate of [Can I change the Android startActivity() transition animation?](http://stackoverflow.com/questions/3515264/can-i-change-the-android-startactivity-transition-animation) – Kristopher Johnson Apr 04 '12 at 22:33

3 Answers3

32

Actually, I've found a property called android:zAdjustment in the animation files.

If I put android:zAdjustment="bottom" in hold.xml (screen 2) and android:zAdjustment="top" in push_down_out.xml (screen 1) then I can get the desired effect.

This gets around the z order issue (I assumed it was an issue with animation timings so I was barking up the wrong tree).

John

johncc
  • 918
  • 1
  • 8
  • 13
30

I've been trying to solve your solution in a sample project and I got it working with this code:

Call the animation with:

startActivity(new Intent(this, Activity2.class));
overridePendingTransition(R.anim.push_down_in,R.anim.push_down_out);

R.anim.push_down_in:

<?xml version="1.0" encoding="utf-8"?>  
<set xmlns:android="http://schemas.android.com/apk/res/android">  
  <translate android:fromYDelta="-100%p" android:toYDelta="0" android:duration="300"/>
</set>  

R.anim.push_down_out:

<?xml version="1.0" encoding="utf-8"?>  
<set xmlns:android="http://schemas.android.com/apk/res/android">  
  <translate android:fromYDelta="0" android:toYDelta="100%p" android:duration="300"/>
</set>  
Romain Piel
  • 11,017
  • 15
  • 71
  • 106
  • 2
    actually if you give different duration for each animation, it give really cool impression. For example for R.anim.push_down_in: `android:duration="900"` and for R.anim.push_down_out: `android:duration="1500"` – mehmet Apr 08 '14 at 10:32
7

The solution that works for me:

R.anim.exit_slide_down

<set xmlns:android="http://schemas.android.com/apk/res/android" 
     android:zAdjustment="top">  

    <translate android:fromYDelta="0" 
               android:toYDelta="100%p" 
               android:duration="600" />
</set>

...and then

Intent intent = new Intent(activity, SecondActivity.class);
startActivity(intent);
activity.overridePendingTransition(0, R.anim.exit_slide_down);
Lukasz R.
  • 2,265
  • 1
  • 24
  • 22