方式一 :overridePendingTransition
public void overridePendingTransition(int enterAnim, int exitAnim)
解释:enterAnim是Activity2进入动画 exitAnim是Activity1退出动画
用法
1、指定进入动画
startActivity(new Intent(Activity1.this,Activity2.class));
overridePendingTransition(R.anim.XXX R.anim.XXY);
2、指定退出动画
@Override
public void finish() {
super.finish();
//参数一:Activity1进入动画,参数二:Activity2退出动画
overridePendingTransition(R.anim.XX1, R.anim.XX2);
}
方式二:自定义android:windowAnimationStyle
用法:
1、设置进入、退出动画
<!-- Activity进出入动画 -->
<style name="AnimationActivity" parent="@android:style/Animation.Activity">
<item name="android:activityOpenEnterAnimation">@anim/activity_slide_enter_right</item>
<item name="android:activityOpenExitAnimation">@anim/activity_slide_exit_left</item>
<item name="android:activityCloseEnterAnimation">@anim/activity_slide_enter_left</item>
<item name="android:activityCloseExitAnimation">@anim/activity_slide_exit_right</item>
</style>
说明:
- activityOpenEnterAnimation Activity2进入动画
- activityOpenExitAnimation Activity1退出动画
- activityCloseEnterAnimation Activity2销毁的时候,Activity1进入的动画
- activityCloseExitAnimation Activity2退出动画
2、android:windowAnimationStyle赋值
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ThemeActivity" parent="android:Theme.Light.NoTitleBar">
<item name="android:windowAnimationStyle">@style/AnimationActivity</item>
</style>
</resources>
最后引用ThemeActivity即可