How to give top to bottom animation in Android?
Asked Answered
C

4

16

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"/>
Cannae answered 13/10, 2011 at 12:22 Comment(0)
S
20

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);
}
Snowplow answered 17/2, 2012 at 4:17 Comment(4)
pls refer #9307013Cannae
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...thanksCannae
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 :)Snowplow
ok hesam sure... ..u r helping me...so i am v thankful of u.. :)Cannae
M
6

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>
Mushro answered 16/6, 2013 at 0:24 Comment(0)
E
5

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.

Exaggerative answered 30/3, 2012 at 12:27 Comment(0)
R
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.

Rebecarebecca answered 13/10, 2011 at 14:1 Comment(2)
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);Cannae
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?Rebecarebecca

© 2022 - 2024 — McMap. All rights reserved.