How to give top to bottom animation in Android?

40,078

Solution 1

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);
}

Solution 2

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>

Solution 3

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.

Solution 4

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.

Share:
40,078
shyam
Author by

shyam

unrecognised.............:(

Updated on July 13, 2020

Comments

  • shyam
    shyam almost 4 years

    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"/>
    
  • shyam
    shyam over 12 years
    i do the same as u said but it is giving same animation means bottom to top but i want top to bottom animation when i press back button ,i reversed the overridePendingTransition(R.anim.slide_out_up, R.anim.slide_in_up);
  • Alesqui
    Alesqui over 12 years
    I do the same as you do guy, except that my "slide_out" animation is android:fromYDelta="0%p" android:toYDelta="100%p". It is working just fine around here. Did you add the extra Intent.FLAG_ACTIVITY_NO_ANIMATION to your Intent when you were going to call the next Activity? Does any animation happen?
  • shyam
    shyam over 12 years
  • shyam
    shyam over 12 years
    hi hesam..want to ask another question pls refer above link if u have ever work wid Bluetooth.. after pairing of 2 devices via Bluetooth how to start exchange profile information with authorization request comes in notification..and after accepting it only exchange profile info..i am getting stuck here from 3 days pls help...thanks
  • Hesam
    Hesam over 12 years
    Hi shyam, I saw your link but unfortunately i have no idea. let me search abut it if i got result then I'll tell you. sorry :)
  • shyam
    shyam over 12 years
    ok hesam sure... ..u r helping me...so i am v thankful of u.. :)