Activity页面切换的动画
2018-05-11 本文已影响0人
Wang_Mr
当手动调用finish发现动画没有生效
@Override
public void startActivity(Intent intent) {
super.startActivity(intent);
// activity切换动画
// 参数一:新Activity进入的动画(最右侧进来)
// 参数二:旧Activity退出的动画(最左侧出去)
overridePendingTransition(R.anim.anim_slide_in_right, R.anim.anim_slide_out_left);
}
@Override
public void startActivityForResult(Intent intent, int requestCode) {
super.startActivityForResult(intent, requestCode);
// activity切换动画
overridePendingTransition(R.anim.anim_slide_in_right, R.anim.anim_slide_out_left);
}
@Override
public void finish() {
super.finish();
// activity切换动画(上一个activity从左侧进入,销毁的activity往右出去)
overridePendingTransition(R.anim.anim_slide_in_left, R.anim.anim_slide_out_right);
}
解决方法:自定义startActivity和finish的动画
<style name="animation_translucent_translate" parent="@android:style/Animation.Translucent">
<item name="android:activityOpenEnterAnimation">@anim/anim_slide_in_right</item>
<item name="android:activityOpenExitAnimation">@anim/anim_slide_out_left</item>
<item name="android:activityCloseEnterAnimation">@anim/anim_slide_in_left</item>
<item name="android:activityCloseExitAnimation">@anim/anim_slide_out_right</item>
</style>
// 如果替换application的style则所有页面生效,替换activity的style则当前activity生效
<item name="android:windowAnimationStyle">@style/activity_open_close_anim</item>