theme-windowAnimationStyle 动画四个方法的意义
首先看代码
<style name="Animation.Activity"> <!--A打开B,B的出现动画--> <item name="activityOpenEnterAnimation">@anim/activity_open_enter</item> <!--A打开B,A的消失动画--> <item name="activityOpenExitAnimation">@anim/activity_open_exit</item> <!--A关闭B,B的出现动画--> <item name="activityCloseEnterAnimation">@anim/activity_close_enter</item> <!--A关闭B,A的消失动画--> <item name="activityCloseExitAnimation">@anim/activity_close_exit</item> </style>
现在我们有两个activity:
VzGalleryActivity(启动者)
AlbumActivity(被启动者)
他们的style分别如下
<style name="PhotoGridLayout"> <item name="android:drawSelectorOnTop">true</item> <item name="android:listSelector">@drawable/photogrid_list_selector</item> </style> <!-- Vanzo:zhangshuli on: Fri, 27 Mar 2015 16:34:18 +0000 --> <style name="AppTheme.Album" parent="@style/AppTheme"> <item name="android:windowAnimationStyle">@style/AnimBottom.Album</item> </style> <style name="AppTheme.VzGallery" parent="@style/AppTheme.Main"> <item name="android:windowAnimationStyle">@style/AnimBottom.VzGallery</item> </style> <style name="AnimBottom.VzGallery" parent="@android:style/Animation.Activity"> <item name="android:activityOpenEnterAnimation">@anim/push_bottom_out</item> <item name="android:activityOpenExitAnimation">@anim/push_bottom_out</item> <item name="android:activityCloseExitAnimation">@anim/push_bottom_out</item> <item name="android:activityCloseEnterAnimation">@anim/push_bottom_out</item> </style> <style name="AnimBottom.Album" parent="@android:style/Animation.Activity"> <item name="android:activityOpenEnterAnimation">@anim/push_bottom_enter</item> <item name="android:activityOpenExitAnimation">@anim/push_bottom_out</item> <item name="android:activityCloseExitAnimation">@anim/push_bottom_enter</item> <item name="android:activityCloseEnterAnimation">@anim/push_bottom_out</item> </style>
两个启动动画分别为
out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="1000" android:fromYDelta="0" android:toYDelta="100%p" /> <alpha android:duration="1000" android:fromAlpha="1.0" android:toAlpha="0.0" /> </set>
enter.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="1000" android:fromYDelta="100%p" android:toYDelta="0" /> <alpha android:duration="1000" android:fromAlpha="0" android:toAlpha="1.0" /> </set>
1)我们更改动画如下
<style name="PhotoGridLayout"> <item name="android:drawSelectorOnTop">true</item> <item name="android:listSelector">@drawable/photogrid_list_selector</item> </style> <!-- Vanzo:zhangshuli on: Fri, 27 Mar 2015 16:34:18 +0000 --> <style name="AppTheme.Album" parent="@style/AppTheme"> <item name="android:windowAnimationStyle">@style/AnimBottom.Album</item> </style> <style name="AppTheme.VzGallery" parent="@style/AppTheme.Main"> <item name="android:windowAnimationStyle">@style/AnimBottom.VzGallery</item> </style> <style name="AnimBottom.VzGallery" parent="@android:style/Animation.Activity"> </style> <style name="AnimBottom.Album" parent="@android:style/Animation.Activity"> <item name="android:activityOpenEnterAnimation">@anim/push_bottom_enter</item> </style>
当,vz启动al的时候,al 有动画效果,
其他情况下,vz,al均没有效果
2)更改如下
<style name="AppTheme.Album" parent="@style/AppTheme"> <item name="android:windowAnimationStyle">@style/AnimBottom.Album</item> </style> <style name="AppTheme.VzGallery" parent="@style/AppTheme.Main"> </style> <style name="AnimBottom.VzGallery" parent="@android:style/Animation.Activity"> <item name="android:activityOpenEnterAnimation">@anim/push_bottom_out</item> <item name="android:activityOpenExitAnimation">@anim/push_bottom_out</item> <item name="android:activityCloseExitAnimation">@anim/push_bottom_out</item> <item name="android:activityCloseEnterAnimation">@anim/push_bottom_out</item> </style> <style name="AnimBottom.Album" parent="@android:style/Animation.Activity"> <item name="android:activityOpenEnterAnimation">@anim/push_bottom_enter</item> <item name="android:activityOpenExitAnimation">@anim/push_bottom_out</item> </style>
vz启动al时候,al跟vz都有动画效果,vz消失动画效果,al出现动画效果
其他情况下没有动画效果(包括al启动其他activity)
3)更改如下
<style name="AppTheme.Album" parent="@style/AppTheme"> <item name="android:windowAnimationStyle">@style/AnimBottom.Album</item> </style> <style name="AppTheme.VzGallery" parent="@style/AppTheme.Main"> </style> <style name="AnimBottom.VzGallery" parent="@android:style/Animation.Activity"> <item name="android:activityOpenEnterAnimation">@anim/push_bottom_out</item> <item name="android:activityOpenExitAnimation">@anim/push_bottom_out</item> <item name="android:activityCloseExitAnimation">@anim/push_bottom_out</item> <item name="android:activityCloseEnterAnimation">@anim/push_bottom_out</item> </style> <style name="AnimBottom.Album" parent="@android:style/Animation.Activity"> <item name="android:activityOpenEnterAnimation">@anim/push_bottom_enter</item> <item name="android:activityOpenExitAnimation">@anim/push_bottom_out</item> <item name="android:activityCloseEnterAnimation">@anim/push_bottom_out</item> </style>
当打开al的时候,al,vz都有动画
但是,关闭al的时候,他们都没有动画
接着,我们通过al,打开另一个activity,al,跟另一个activity没有动画,
最后,我们关闭al打开的activity的时候,al有动画,其他相关activity没有动画
4)更改如下
<style name="AppTheme.Album" parent="@style/AppTheme"> <item name="android:windowAnimationStyle">@style/AnimBottom.Album</item> </style> <style name="AppTheme.VzGallery" parent="@style/AppTheme.Main"> </style> <style name="AnimBottom.VzGallery" parent="@android:style/Animation.Activity"> <item name="android:activityOpenEnterAnimation">@anim/push_bottom_out</item> <item name="android:activityOpenExitAnimation">@anim/push_bottom_out</item> <item name="android:activityCloseExitAnimation">@anim/push_bottom_out</item> <item name="android:activityCloseEnterAnimation">@anim/push_bottom_out</item> </style> <style name="AnimBottom.Album" parent="@android:style/Animation.Activity"> <item name="android:activityOpenEnterAnimation">@anim/push_bottom_enter</item> <item name="android:activityOpenExitAnimation">@anim/push_bottom_out</item> <item name="android:activityCloseEnterAnimation">@anim/push_bottom_out</item> <item name="android:activityCloseExitAnimation">@anim/push_bottom_enter</item> </style>
打开al的时候,al,vz都有动画
关闭al的时候,都没有动画
al打开另外一个activity的时候,都没有动画
当另一个activity结束的时候,al跟另一个activity都有动画
我们可以得出如下结论
(1)这四个属性,针对的都是自己
(2)open属性,是自己被打开的时候的相关动画,也就是自己出现的时候(被打开),其实就是自己跟父activity的动画情况
close属性,是自己消失的时候的动画属性(打开别人),其实就是自己跟子activity的动画情况
(3)enter属性,是出现在屏幕中,自己或者跟自己相关的其他activity
exit属性,是退出屏幕,自己或者跟自己相关的activity