overridePendingTransition shows second activity to

2019-04-04 13:24发布

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.

2条回答
Ridiculous、
2楼-- · 2019-04-04 13:45

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);
查看更多
\"骚年 ilove
3楼-- · 2019-04-04 13:51

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.

查看更多
登录 后发表回答