Activity的跳转动画在5.0的时候做了一个重大的突破,下面来看一下吧
//此activity进入
getWindow().setEnterTransition(new Explode().setDuration(2000));
//此activity退出
getWindow().setExitTransition(new Explode().setDuration(2000));
//再次进入时使用(如果当前Activity已经打开过,并且再次打开该Activity时的动画 )
//getWindow().setReenterTransition(new Explode().setDuration(2000));
//决定在两个Activity之间切换时,指定两个Activity中对应的View的过渡效果
// getWindow().setSharedElementEnterTransition(new Explode().setDuration(2000));
Transition explode = TransitionInflater.from(this).inflateTransition(R.transition.explode);
getWindow().setEnterTransition(explode);
getWindow().setExitTransition(explode);
- @transition/explode
- @transition/explode
- @transition/explode
getWindow().setEnterTransition(new Fade().setDuration(2000));
getWindow().setExitTransition(new Fade().setDuration(2000));
//左侧滑入
getWindow().setEnterTransition(new Slide(Gravity.LEFT).setDuration(2000));
getWindow().setExitTransition(new Slide(Gravity.RIGHT).setDuration(2000));
startActivity(intent,ActivityOptions.makeSceneTransitionAnimation(this,button,"all_hava").toBundle());
startActivity(intent,ActivityOptions.makeSceneTransitionAnimation(this,button,"all_hava").toBundle());
}else{
a. //低版本兼容,不过没动画效果 http://www.cnblogs.com/tianzhijiexian/p/4087917.html 可以看下这个介绍
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeScaleUpAnimation(
button,
0,
0,
0,
0);
ActivityCompat.startActivity(this,intent,optionsCompat.toBundle());
b. //或者是直接用overridePendingTransition();
}
兼容5.0以下的转场动画
可以看下http://www.jianshu.com/p/340c938e9f32 (翻译版)
https://medium.com/@aitorvs/android-shared-element-transitions-for-all-b90e9361507d(原文版)