Activity的启动过程请参考罗升阳的文章
Activity生命周期:
Activity xml文件中android:theme使用方法
总结:
android:theme="@android:style/Theme.Dialog" 将一个Activity显示为能话框模式
android:theme="@android:style/Theme.NoTitleBar" 不显示应用程序标题栏
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 不显示应用程序标题栏,并全屏
android:theme="Theme.Light" 背景为白色
android:theme="Theme.Light.NoTitleBar" 白色背景并无标题栏
android:theme="Theme.Light.NoTitleBar.Fullscreen" 白色背景,无标题栏,全屏
android:theme="Theme.Black" 背景黑色
android:theme="Theme.Black.NoTitleBar" 黑色背景并无标题栏
android:theme="Theme.Black.NoTitleBar.Fullscreen" 黑色背景,无标题栏,全屏
android:theme="Theme.Wallpaper" 用系统桌面为应用程序背景
android:theme="Theme.Wallpaper.NoTitleBar" 用系统桌面为应用程序背景,且无标题栏
android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" 用系统桌面为应用程序背景,无标题栏,全屏
android:theme="Translucent" 半透明
android:theme="Theme.Translucent.NoTitleBar" 半透明、无标题栏
android:theme="Theme.Translucent.NoTitleBar.Fullscreen" 半透明、无标题栏、全屏
android:theme="Theme.Panel"
android:theme="Theme.Light.Panel"
android:theme="@android:style/Theme.NoTitleBar" 不显示应用程序标题栏
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 不显示应用程序标题栏,并全屏
android:theme="Theme.Light" 背景为白色
android:theme="Theme.Light.NoTitleBar" 白色背景并无标题栏
android:theme="Theme.Light.NoTitleBar.Fullscreen" 白色背景,无标题栏,全屏
android:theme="Theme.Black" 背景黑色
android:theme="Theme.Black.NoTitleBar" 黑色背景并无标题栏
android:theme="Theme.Black.NoTitleBar.Fullscreen" 黑色背景,无标题栏,全屏
android:theme="Theme.Wallpaper" 用系统桌面为应用程序背景
android:theme="Theme.Wallpaper.NoTitleBar" 用系统桌面为应用程序背景,且无标题栏
android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" 用系统桌面为应用程序背景,无标题栏,全屏
android:theme="Translucent" 半透明
android:theme="Theme.Translucent.NoTitleBar" 半透明、无标题栏
android:theme="Theme.Translucent.NoTitleBar.Fullscreen" 半透明、无标题栏、全屏
android:theme="Theme.Panel"
android:theme="Theme.Light.Panel"
1、A - B
04-27 13:37:47.512 11505-11505/com.lj.cheat E/--: --ActivityA onPause finish
04-27 13:37:47.559 11505-11505/com.lj.cheat E/--: --ActivityB onStart finish
04-27 13:37:47.559 11505-11505/com.lj.cheat E/--: --ActivityB onResume finish
04-27 13:37:48.090 11505-11505/com.lj.cheat E/--: --ActivityA onStop finish
04-27 13:37:47.559 11505-11505/com.lj.cheat E/--: --ActivityB onStart finish
04-27 13:37:47.559 11505-11505/com.lj.cheat E/--: --ActivityB onResume finish
04-27 13:37:48.090 11505-11505/com.lj.cheat E/--: --ActivityA onStop finish
原因是:B可见之前,A不可见
2、
单例Activity:A 走
onNewIntent 之后 ,还会执行
onStart onPause函数
A - A
onNewIntent
04-27 17:56:56.307 22667-22667/com.lj.cheat E/--: --ActivityA onPause finish
04-27 17:56:56.309 22667-22667/com.lj.cheat E/--: --ActivityA onNewIntent finish
04-27 17:56:56.310 22667-22667/com.lj.cheat E/--: --ActivityA onResume finish
A - B - A
onNewIntent
04-27 17:52:34.929 17486-17486/com.lj.cheat E/--: --ActivityB onPause finish
04-27 17:52:34.950 17486-17486/com.lj.cheat E/--: --ActivityA onNewIntent finish
04-27 17:52:34.953 17486-17486/com.lj.cheat E/--: --ActivityA onStart finish
04-27 17:52:34.953 17486-17486/com.lj.cheat E/--: --ActivityA onResume finish
04-27 17:52:35.418 17486-17486/com.lj.cheat E/--: --ActivityB onStop finish
onNewIntent
04-27 17:56:56.307 22667-22667/com.lj.cheat E/--: --ActivityA onPause finish
04-27 17:56:56.309 22667-22667/com.lj.cheat E/--: --ActivityA onNewIntent finish
04-27 17:56:56.310 22667-22667/com.lj.cheat E/--: --ActivityA onResume finish
A - B - A
onNewIntent
04-27 17:52:34.929 17486-17486/com.lj.cheat E/--: --ActivityB onPause finish
04-27 17:52:34.950 17486-17486/com.lj.cheat E/--: --ActivityA onNewIntent finish
04-27 17:52:34.953 17486-17486/com.lj.cheat E/--: --ActivityA onStart finish
04-27 17:52:34.953 17486-17486/com.lj.cheat E/--: --ActivityA onResume finish
04-27 17:52:35.418 17486-17486/com.lj.cheat E/--: --ActivityB onStop finish
Activity 之间的过渡动画,共享元素
5.0上采用下面api方便实现过度动画
android.app.ActivityOptions#makeSceneTransitionAnimation
建议参考:
https://github.com/lgvalle/Material-Animations
建议参考:
https://github.com/lgvalle/Material-Animations
5.0之前低版本实现Activity共享元素使用属性动画
下面首页搜索框动画为例,如图所示:
A->B假如A跳转B
方案1:将搜索布局父布局整体上移,同时向左移动每一个元素。元素间相互干扰导致动画抖动。
方案2:
1、计算出origin布局距离视图移动的总距离,传递给ActivityB。
2、B背景设置为透明,计算出每个元素各自移动的距离。
3、为了衔接更加流畅,在动画开始的时候,使用EventBus通知A的origin布局逐渐隐藏。
补刀:为了使动画更加流畅,共享动画更加逼真,我们将白色背景和搜索背景分开,分别移动。
动画之间有相互依赖的时候,或者一个组件即在X轴移动,又在Y轴移动,则会出现图片压缩,拉伸问题,因此单独移动放大镜
参考文献:
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2016/0901/6590.html
https://github.com/lgvalle/Material-Animations
https://juejin.im/entry/586d043a1b69e600630039ee
https://github.com/lgvalle/Material-Animations
https://juejin.im/entry/586d043a1b69e600630039ee
附录
爱奇艺首页效果可以采用第二种实现方案总体效果,图片太大,无法上传,需要的同学可以留邮箱单发
爱奇艺首页效果可以采用第二种实现方案模仿效果如下: