overridePendingTransition shows second activity too quickly

19,882

Solution 1

Nevermind, that was a dumb error - i didn't understand what the documentation meant by "entering animation" vs "exiting animation". i need to swap the xmls by changing:

FirstActivity.this.overridePendingTransition(R.anim.slide, R.anim.slide2);

into

FirstActivity.this.overridePendingTransition(R.anim.slide2, R.anim.slide);

Solution 2

just add these to your slide2.xml:

android:startOffset="2000"

this way the animation for the 2nd activity will only start right after your 1st activity's animation is complete.

Share:
19,882
David T.
Author by

David T.

Junior Android developer coming here on Stack Overflow to improve my coding abilities game dev experience (iOS, Android & OUYA + others)

Updated on June 05, 2022

Comments

  • David T.
    David T. almost 2 years

    i have 2 activities, and i want to create an animated transition between the two activities such that both activities's views slides up as if the second activity is pushing the first activity upwards. in my first activity i use:

    Intent iSecondActivity = new Intent(FirstActivity.this,SecondActivity.class);
    FirstActivity.this.startActivity(iSecondActivity);
    FirstActivity.this.overridePendingTransition(R.anim.slide, R.anim.slide2);
    

    and my slide.xml looks like:

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/accelerate_interpolator">
        <translate
            android:interpolator="@android:anim/decelerate_interpolator"
            android:fromYDelta="0"
            android:toYDelta="-100%p"
            android:duration="2000"
        />
    </set>
    

    and my slide2.xml looks like:

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/accelerate_interpolator">
        <translate
             android:interpolator="@android:anim/decelerate_interpolator"
             android:fromYDelta="100%p"
             android:toYDelta="0"
             android:duration="2000"
        />
    </set>
    

    HOWEVER, the problem is that when the "startActivity" is called, the second activity's view is already rendered while the transition just starts sliding. I would like to see the first activity's view slide up... but instead i'm seeing the second activity's view (rendered over the first activity's view) slide up.

    the second problem is that i'm seeing the replacement view being the first activity's view. i would like the replacement view to be the second activity's view that is pushing upwards.

    It's hard to explain, so please let me know if i can explain anything in more detail. apologies for any confusion, and thanks for reading this.

    P.S. i'm using textviews... i guess that renders too quickly? I'm also using Motorola Razr, not that it should matter.