安卓动画详解——补间动画
2016-01-12 17:22
447 查看
AlphaAnimation
为视图增加透明度的变化动画。
使用Java代码定义AlphaAnimation动画
使用XML资源文件设定AlphaAnimation
RotateAnimation
为视图增加旋转的变换动画
TranslateAnimation
为视图移动时增加位移动画
ScaleAnimation
为视图的缩放增加动画效果
AnimationSet
为视图增加透明度的变化动画。
使用Java代码定义AlphaAnimation动画
private void toAlpha(){ //0为透明,1为不透明 AlphaAnimation anim=new AlphaAnimation(0,1); //设置动画播放时间 anim.setDuration(200); //设置动画播放结束后保持播放之后的效果 anim.setFillAfter(true); //设置重复次数 <0 无限循环 anim.setRepeatCount(-1); anim.setRepeatMode(Animation.REVERSE); iv.setAnimation(anim); }
使用XML资源文件设定AlphaAnimation
protected void toAlpha() { Animation anim=AnimationUtils.loadAnimation(Activity.this, R.anim.anim_alpha); iv.startAnimation(anim); } <?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="200" android:fillAfter="true" android:fromAlpha="0.0" android:repeatCount="-1" android:repeatMode="reverse" android:toAlpha="1.0" > </alpha>
RotateAnimation
为视图增加旋转的变换动画
private void toRotate(){ //其参数分别为旋转的起始角度 起始坐标 旋转参考系为自身中心 RotateAnimation anim=new RotateAnimation(0,360,RotateAnimation.RELATIVE_TO_SELF,0.5f,RotateAnimation.RELATIVE_TO_SELF,0.5f); anim.setDuration(2000); anim.setRepeatCount(-1); //LinearInterpolator 动画以均匀的速率改变 //AccelerateDecelerateInterpolator 在动画开始与结束的地方速率改变比较慢,在中间的时候加速 //AccelerateInterpolator 在动画开始的地方速率比较慢,然后开始加速 //CycleInterpolator 动画循环播放特定次数,速率改变沿着正弦曲线 //DecelerateInterpolator 在动画开始的地方速率改变比较慢 然后开始减速 anim.setInterpolator(new LinearInterpolator()); iv.setAnimation(anim); } }
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:repeatCount="2" android:toDegrees="360" > </rotate>
TranslateAnimation
为视图移动时增加位移动画
private void toTranslate(){ TranslateAnimation anim=new TranslateAnimation(0,500,0,500); anim.setDuration(2000); anim.setRepeatCount(-1); anim.setRepeatMode(Animation.REVERSE); iv.setAnimation(anim); }
<?xml version="1.0" encoding="utf-8"?> <translate xmlns:android="http://schemas.android.com/apk/res/android" android:fromXDelta="10%p" android:toXDelta="20%p" android:fromYDelta="10%p" android:toYDelta="20%p" android:duration="2000" android:repeatCount="2" android:repeatMode="reverse"> </translate>
ScaleAnimation
为视图的缩放增加动画效果
private void toScale(){ ScaleAnimation anim=new ScaleAnimation(0,2,0,2, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f ); anim.setDuration(2000); anim.setRepeatCount(-1); anim.setRepeatMode(Animation.REVERSE); iv.setAnimation(anim); }
<?xml version="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000" android:pivotX="50%" android:pivotY="50%" android:fromXScale="0.2" android:fromYScale="0.2" android:toXScale="2.0" android:toYScale="2.0" > </scale>
AnimationSet
private void toSetAnim(){ AnimationSet as=new AnimationSet(true); as.setDuration(1000); TranslateAnimation anim1=new TranslateAnimation(0,0,0,500); anim1.setDuration(1000); anim1.setRepeatCount(-1); anim1.setRepeatMode(Animation.REVERSE); as.addAnimation(anim1); RotateAnimation anim2=new RotateAnimation(0,360,RotateAnimation.RELATIVE_TO_SELF,0.5f,RotateAnimation.RELATIVE_TO_SELF,0.5f); anim2.setDuration(1000); anim2.setRepeatCount(-1); anim2.setRepeatMode(Animation.REVERSE); as.addAnimation(anim2); iv.startAnimation(as); }
相关文章推荐
- OS之子进程简单模拟shell解释环境(再次)
- 使用ANR-WatchDog来检測ANR
- Hadoop端口一览表
- 利用systemd 实现 tomcat 多实例
- ZOJ 3881 From the ABC conjecture
- Paths - 2
- MAC下检查是否安装command line tools 工具
- 学习OC 问题1: 关于“ARC forbids explicit message send of release”错误
- java.lang.OutOfMemoryError
- 相较于其他语言,golang的突出特点和优势
- 关于java Udp收发数据异常的笔记
- nginx源码学习资源
- Hadoop端口一览表
- 【转】学习apicloud和IOS之间的模块化使用
- 装逼的苹果审核指南
- (转) 机器学习与数据挖掘网上资源搜罗——良心推荐
- find命令之时间戳使用示例
- bash脚本编程 条件判断 二
- python 装饰器模式 我的理解
- IOS上 关于状态栏的相关设置(UIStatusBar)