Android 技术专题Feature系列第一篇 四大组件之Activity

Activity的启动过程请参考罗升阳的文章
Activity生命周期:

oncreate
initUi,managedQuery
onResume
startanimations,opencamera
onPause
stopanimations,closecamera

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" 

Activity 易错的生命周期
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
原因是: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

Activity 之间的过渡动画,共享元素
5.0上采用下面api方便实现过度动画
android.app.ActivityOptions#makeSceneTransitionAnimation
建议参考:
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


附录
爱奇艺首页效果可以采用第二种实现方案总体效果,图片太大,无法上传,需要的同学可以留邮箱单发


爱奇艺首页效果可以采用第二种实现方案模仿效果如下:
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值