在360通话程序上还有一个功能就是来去点跳出来的windowmanager会以动画的效果显示。
在网上寻找并看了很多帖子都没有,于是只有找源码发现有一个android自带资源android.R.style.Animation_Translucent可以基本满足以上要求,但是这是自带的,只能进行窗口平移,不能自由组合动画。在sdk里翻了半天找到了文件所在:
SDK ---> platforms ---> android-21 ---> data ---> res
这是自带所有资源的位置了,并找了很多相关源码想仿照上面来自己写,其中主要文件有styes.xml,translucent_enter.xml,translucent_exit.xml,attrs.xml这几个文件都是和动画资源相关的。从里面看到,windowmanager真正需要的是style资源,而不知一个普通的动画xml文件,然后则是两个动画xml文件代替来显示并退出窗口,最后则是两个属性在attrs.xml文件中定义。
所以知道大概后就可以写了
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<alpha
android:duration="1000"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<alpha
android:duration="1000"
android:fromAlpha="1.0"
android:toAlpha="0.0" >
</alpha>
</set>
两个基本动画,然后则是在style中将两者关联
<style name="AnimationTranslucent">
<item name="@android:windowEnterAnimation">@anim/windowmanager</item>
<item name="@android:windowExitAnimation">@anim/nowindowmanager</item>
</style>
将上述动画添加到windowmanager中
// 添加动画以开启
params.windowAnimations = R.style.AnimationTranslucent;
这就基本完成了整体功能。