Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Activity Transition Animation

What I am trying to achieve is : start a new activity with a transition animation for the exiting activity only.

I would like to slide up the current activity, where the new activity will be behind the current one.

Here is the slide up animation : R.layout.slide_up

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

    <translate
        android:duration="1000"
        android:fromYDelta="0%"
        android:toYDelta="100%" />

</set>

Here is how I am applying the activity animation transition :

overridePendingTransition ( 0 , R.anim.slide_up );

I am using 0 for the entering activity since I do not want any animation for the new activity, and it is not working (the animation is not performed). If I use an animation for entering activity too, it works (both animations are performed), like such :

overridePendingTransition ( R.anim.slide_out , R.anim.slide_up );

where R.anim.slide_out :

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

    <translate
        android:duration="1000"
        android:fromYDelta="100%"
        android:toYDelta="0%" />

</set>

Any ideas ?

I am working on Android 4.1.2 and Android 4.0.4

like image 237
Leeeeeeelo Avatar asked Feb 26 '13 13:02

Leeeeeeelo


People also ask

What is transition animation in Android?

Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.


2 Answers

Alter your exit animation so that it renders over top of the entering activity.

R.anim.slide_up

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

    <translate
        android:duration="1000"
        android:fromYDelta="0%"
        android:toYDelta="100%" />

</set>

Then you can do what you were originally doing to set the animation.

overridePendingTransition ( 0 , R.anim.slide_up );
like image 172
Michael Celey Avatar answered Sep 17 '22 21:09

Michael Celey


Call the below method after startActivity method.

 overridePendingTransition(0,0);

This will override the default animation and do no animation. You can also give some custom animation if you like

overridePendingTransition(R.anim.animation1,R.anim.animation2);

like image 21
TanvirChowdhury Avatar answered Sep 20 '22 21:09

TanvirChowdhury