overridePendingTransition shows second activity too quickly

妖精的绣舞 提交于 2019-12-09 14:40:55

问题


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.


回答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);



回答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.



来源:https://stackoverflow.com/questions/10117910/overridependingtransition-shows-second-activity-too-quickly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!