void android.app.Activity.overridePendingTransitio n(int enterAnim, int exitAnim)
public void overridePendingTransitio n (int enterAnim, int exitAnim)
Since:
API Level 5
Call immediately after one of the flavors of startActivity(Intent)
or finish()
to specify an explicit transition animation to perform next.
Parameters
enterAnim | A resource ID of the animation resource to use for the incoming activity. Use 0 for no animation. |
---|---|
exitAnim | A resource ID of the animation resource to use for the outgoing activity. Use 0 for no animation. |
-----------------------------------------------------------------------------------------------
在代码中,我们只需要实现如下:
Intent intent = new Intent();
intent.setClass(TestActivity.this, MyActivity.class);
startActivity(intent);
overridePendingTransitio
n(R.anim.in_from_right, R.anim.out_to_left);//这里的enterAnim和exitAnim可以自己发挥
这两个resource file是放在res目录下的anim目录中。下面写两个简单的animation:
-------------------------------
in_from_right.xml-------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
</set>
------------------------------------
out_to_left.xml----------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
</set>