[android] 帧动画和补间动画
2016-04-20 22:00
393 查看
逐帧显示一张图片,连起来成为动画
在res/drawable/目录下,创建一个xxx.xml的文件
添加<animation-list>节点,设置是否循环android:oneshot:”false”
添加条目<item>节点,设置资源android:drawable=”@drawable/xxx”
设置执行时间,android:duration=”100”
逐帧添加对应的图片
获取ImageView对象,通过findViewById()
调用ImageView对象的setBackgroundResource()设置背景资源,参数:资源文件
调用ImageView对象的getBackground()方法获取到AnimationDrawable对象
getBackground()方法是异步的在一个单独的线程里面执行的,因此,有时候,下面的代码是播放不了的,建议放在按钮点击事件里,或者屏幕触摸事件里
调用AnimationDrawable对象start()方法,开始播放
tween动画
透明度
获取AlphaAnimation对象,new AlphaAnimation(),参数:从0.0f透明度,到1.0f透明度
AlphaAnimation对象的setDuration()方法,设置执行时间
调用View对象的startAnimation()方法,参数:AlphaAnimation对象
缩放
获取ScaleAnimation对象,new ScaleAnimation(),参数:
原始宽,变化后宽,原始高,变化后高,Animation.RELATIVE_TO_SELF,o.5f x以中心,Animation.RELATIVE_TO_SELF,0.5f y以中心
调用View对象的startAnimation()方法,参数:ScaleAnimation对象
旋转
获取RotateAnimation对象,new RotateAnimation(),参数:
从0开始选择,旋转360度,旋转中心Animation.RELATIVE_TO_SELF,o.5f x以中心,旋转中心Animation.RELATIVE_TO_SELF,o.5f x以中心
调用View对象的startAnimation()方法,参数:RotateAnimation对象
平移
获取TranslateAnimation对象,new TranslateAnimation(),参数:
相对于父窗体Animation.RELATIVE_TO_PARENT,0.0f
相对于父窗体Animation.RELATIVE_TO_PARENT,1.0f
相对于父窗体Animation.RELATIVE_TO_PARENT, 0.0f
相对于父窗体Animation.RELATIVE_TO_PARENT, 1.0f
调用View对象的startAnimation()方法,参数:TranslateAnimation对象
组合动画
获取AnimationSet对象,new出来
获取到上面的多个动画对象
调用AnimationSet对象的addAnimation()方法,把动画添加进来,参数:动画
多次添加就可以了
调用View对象的startAnimation()方法,参数:AnimationSet对象
在res/drawable/目录下,创建一个xxx.xml的文件
添加<animation-list>节点,设置是否循环android:oneshot:”false”
添加条目<item>节点,设置资源android:drawable=”@drawable/xxx”
设置执行时间,android:duration=”100”
逐帧添加对应的图片
获取ImageView对象,通过findViewById()
调用ImageView对象的setBackgroundResource()设置背景资源,参数:资源文件
调用ImageView对象的getBackground()方法获取到AnimationDrawable对象
getBackground()方法是异步的在一个单独的线程里面执行的,因此,有时候,下面的代码是播放不了的,建议放在按钮点击事件里,或者屏幕触摸事件里
调用AnimationDrawable对象start()方法,开始播放
tween动画
透明度
获取AlphaAnimation对象,new AlphaAnimation(),参数:从0.0f透明度,到1.0f透明度
AlphaAnimation对象的setDuration()方法,设置执行时间
调用View对象的startAnimation()方法,参数:AlphaAnimation对象
缩放
获取ScaleAnimation对象,new ScaleAnimation(),参数:
原始宽,变化后宽,原始高,变化后高,Animation.RELATIVE_TO_SELF,o.5f x以中心,Animation.RELATIVE_TO_SELF,0.5f y以中心
调用View对象的startAnimation()方法,参数:ScaleAnimation对象
旋转
获取RotateAnimation对象,new RotateAnimation(),参数:
从0开始选择,旋转360度,旋转中心Animation.RELATIVE_TO_SELF,o.5f x以中心,旋转中心Animation.RELATIVE_TO_SELF,o.5f x以中心
调用View对象的startAnimation()方法,参数:RotateAnimation对象
平移
获取TranslateAnimation对象,new TranslateAnimation(),参数:
相对于父窗体Animation.RELATIVE_TO_PARENT,0.0f
相对于父窗体Animation.RELATIVE_TO_PARENT,1.0f
相对于父窗体Animation.RELATIVE_TO_PARENT, 0.0f
相对于父窗体Animation.RELATIVE_TO_PARENT, 1.0f
调用View对象的startAnimation()方法,参数:TranslateAnimation对象
组合动画
获取AnimationSet对象,new出来
获取到上面的多个动画对象
调用AnimationSet对象的addAnimation()方法,把动画添加进来,参数:动画
多次添加就可以了
调用View对象的startAnimation()方法,参数:AnimationSet对象
相关文章推荐
- Android 2.3.5/4.0.3/4.1PowerManager简单总结和心得体会
- Android学习(31) --对话框&单选对话框&多选对话框
- Android学习(30) -- ArrayAdapter&SimpleAdapter
- Android反编译后重新打包
- Android线上bug热修复分析
- Android 使用GridView以表格的形式显示多张图片
- Android 自定义相机 切换相机 参考线(辅助线) 闪光灯 缩放 自动聚焦 Demo
- 团队开发任务01 搭建Android环境
- 【Android】Android之创建活动
- Android Looper详解
- Android DEX安全攻防战
- Android之Activity的生命周期
- Android四大控件之ContentProvider
- android中的通信机制总结
- Android 图片转化工具类BitmapUtil
- Android中通知栏的使用
- android 内存优化
- Android复习笔记--Intent
- Android复习笔记--Activity
- Android内置so库到各个目录下