0

I have declared two custom animations, which are working fine on a HTC Desire s running android 2.3.5 with HTC Sense 3.5 (custom ROM, Endymion V3.5, so I can test on OS before ICS). On opening a new activity, the new screen slides in from the right, on closing the currenty activity, the new screen slides in from the left, so it is all good. The code I have is:

overridePendingTransition(com.my.app.R.anim.slidein, com.my.app.R.anim.slideout);

The xmls declaring the animations are the following:

slidein.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="100%p" android:toXDelta="0"
           android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="1.0" android:toAlpha="1.0"
       android:duration="@android:integer/config_mediumAnimTime" />

slideout.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-100%p"
           android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="1.0" android:toAlpha="1.0"
       android:duration="@android:integer/config_mediumAnimTime" />

However, here comes the problem.

The same apk does partially work on Nexus4. When openning a new activity, it works correctly, the new screen slides in from the right. When closing the currenty activity, the previous screen just appears with the default animation, ignoring my custom animation. I have Unofficial CM 10.2, with android 4.3 on my Nexus4.

My question is: is it supposed to work like this on android 4.3? Maybe on newer API level, there is another method, that I need to call in order to get this right? Any help is appreciated!

Cheers

EDIT: I declared custom exit animations, separetely, and combining with the suggested solution, it is now working as expected.

closeslidein.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-100%p" android:toXDelta="0"
           android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="1.0" android:toAlpha="1.0"
       android:duration="@android:integer/config_mediumAnimTime" />

closeslideout.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="100%p"
           android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="1.0" android:toAlpha="1.0"
       android:duration="@android:integer/config_mediumAnimTime" />

And the finishing proccess:

@Override
public void finish()
{
    super.finish();
    overridePendingTransition(com.my.app.R.anim.closeslidein, com.my.app.R.anim.closeslideout);
}
4

1 回答 1

1

确保正确调用。如果您是finish()显式调用,那么您需要 overridePendingTransition()在它之后立即调用。如果您没有finish()明确调用,那么您需要覆盖onBackPressed()并调用overridePendingTransition()它。

于 2013-10-08T08:18:01.987 回答