Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give top to bottom animation in Android?

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"/>
like image 322
shyam Avatar asked Oct 13 '11 12:10

shyam


4 Answers

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);
}
like image 154
Hesam Avatar answered Nov 19 '22 09:11

Hesam


Worked on my tablet 4.0.3.

slide_out_up.xml:

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

    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromYDelta="0%p"
        android:toYDelta="-100%p" />

</set>

slide_in_up:xml:

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

    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromYDelta="-100%p"
        android:toYDelta="0%p" />

</set>

style.xml:

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

    <style name="DialogAnimationOutUpInUp">
        <item name="android:windowEnterAnimation">@anim/slide_in_up</item>
        <item name="android:windowExitAnimation">@anim/slide_out_up</item>
    </style>

</resources>
like image 23
Yura Shinkarev Avatar answered Nov 19 '22 11:11

Yura Shinkarev


i just implemented it with two more xml files having like

slide up, 100 to 0 and 0 to -100

slide down -100 to 0 and 0 to 100

it works perfect.

like image 5
cavallo Avatar answered Nov 19 '22 10:11

cavallo


You can override the back button press behavior and set the appropriate animation that you want, like this:

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

Change the animations at the overridePendingTransition so that it fits the ones that you want.

like image 4
Alesqui Avatar answered Nov 19 '22 10:11

Alesqui