How to give top to bottom animation in Android?

shyam picture shyam · Oct 13, 2011 · Viewed 39.1k times · Source

I am able to give bottom to top animation when I go to next activity but now when I pressed back I am using same code for giving animation from top to bottom animation but it always goes to bottom to top so my question is how to give animation from top to bottom when i pressed back button on android device?
Please find my code below.

I use it during transitioning from one Activity to another using an Intent.

overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );

and xml is: slide_in_up.xml

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

and slide_out_up.xml is

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

Answer

Hesam picture Hesam · Feb 17, 2012

Just Change -100 to 100 (remove minus) in slide_out_up.xml

@Override
public void onBackPressed() {
    finish();
    overridePendingTransition(R.anim.enter_anim, R.anim.exit_anim);
}