android 四种动画TranslateAnimation,ScaleAnimation,RotateAnimation,AlphaAnimation
来源:互联网 发布:mac安装win7虚拟机教程 编辑:程序博客网 时间:2024/05/20 23:58
这四种补间动画都是Animation的子类。
移动补间动画:TranslateAnimation
Animation animation = new TranslateAnimation(0,50,0,50);
参数1:x轴的起始位置
参数2:x轴的终止位置
参数3:y轴的起始位置
参数4:y轴的终止位置
相对于原图位置的原点(图片的右上角为0,0),如果不想用这个点作为参照点,可以使用其他构造
Animation animation = new TranslateAnimation(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue);
参数1,参数3,参数5,参数7就是设置参照点的方式
可以通过Animation类的常量进行设置例如:Animation.RELATIVE_TO_SELF
缩放补间动画:ScaleAnimation
Animation animation = new ScaleAnimation(1f,0.2f,1f,0.2f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
参数1:x方向起始大小(1f表示原图大小)
参数2:x方向终止大小(0.2f表示原图的0.2倍)
参数3:y方向起始大小(1f表示原图大小)
参数4:y方向终止大小(0.2f表示原图的0.2倍)
参数5:缩放中心点x轴取值的参照方式
参数6:中心点x轴的取值(0.5f表示相对与原图的0.5倍)
参数7:缩放中心点y轴取值参照方式
参数8:中心点y轴的取值(0.5f表示相对与原图的0.5倍)
旋转补间动画:RotateAnimation
Animation animation = new RotateAnimation(360,0,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
参数1:旋转的起始角度
参数2:旋转的终止角度
参数3:旋转中心的x轴取值参照方式
参数4:中心点x轴的取值
参数5:旋转中心的y轴取值参照方式
参数6:中心点y轴的取值
透明补间动画:AlphaAnimation
Animation animation = new AlphaAnimation(1f,0.1f);
参数1: 起始透明度;
参数2: 目标透明度;
每种动画都有很多种重载,可以根据需求进行选择,如果想让动画有效果还得设置动画的时间
设置动画持续时间
animation.setDuration(2000);
以毫秒为单位
对于动画还可以设置渲染器
android系统提供了很多渲染器资源 通过android.R.anim.的方式使用(在res目录下的anim目录下定义)
animation.setInterpolator(Main.this,android.R.anim.anticipate_overshoot_interpolator);
如果想要多个动画效果同时使用,可以通过AnimationSet 实现
AnimationSet animationSet = new AnimationSet(false);
animationSet.addAnimation(animation);
得到动画对象之后就是使用了,每个view都有startAnimation(animation)方法
因为AnimationSet继承自Animation类所以该方法的参数既可以是动画对象(Animation)也可以是动画集(AnimationSet )对象
移动补间动画:TranslateAnimation
Animation animation = new TranslateAnimation(0,50,0,50);
参数1:x轴的起始位置
参数2:x轴的终止位置
参数3:y轴的起始位置
参数4:y轴的终止位置
相对于原图位置的原点(图片的右上角为0,0),如果不想用这个点作为参照点,可以使用其他构造
Animation animation = new TranslateAnimation(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue);
参数1,参数3,参数5,参数7就是设置参照点的方式
可以通过Animation类的常量进行设置例如:Animation.RELATIVE_TO_SELF
缩放补间动画:ScaleAnimation
Animation animation = new ScaleAnimation(1f,0.2f,1f,0.2f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
参数1:x方向起始大小(1f表示原图大小)
参数2:x方向终止大小(0.2f表示原图的0.2倍)
参数3:y方向起始大小(1f表示原图大小)
参数4:y方向终止大小(0.2f表示原图的0.2倍)
参数5:缩放中心点x轴取值的参照方式
参数6:中心点x轴的取值(0.5f表示相对与原图的0.5倍)
参数7:缩放中心点y轴取值参照方式
参数8:中心点y轴的取值(0.5f表示相对与原图的0.5倍)
旋转补间动画:RotateAnimation
Animation animation = new RotateAnimation(360,0,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
参数1:旋转的起始角度
参数2:旋转的终止角度
参数3:旋转中心的x轴取值参照方式
参数4:中心点x轴的取值
参数5:旋转中心的y轴取值参照方式
参数6:中心点y轴的取值
透明补间动画:AlphaAnimation
Animation animation = new AlphaAnimation(1f,0.1f);
参数1: 起始透明度;
参数2: 目标透明度;
每种动画都有很多种重载,可以根据需求进行选择,如果想让动画有效果还得设置动画的时间
设置动画持续时间
animation.setDuration(2000);
以毫秒为单位
对于动画还可以设置渲染器
android系统提供了很多渲染器资源 通过android.R.anim.的方式使用(在res目录下的anim目录下定义)
animation.setInterpolator(Main.this,android.R.anim.anticipate_overshoot_interpolator);
如果想要多个动画效果同时使用,可以通过AnimationSet 实现
AnimationSet animationSet = new AnimationSet(false);
animationSet.addAnimation(animation);
得到动画对象之后就是使用了,每个view都有startAnimation(animation)方法
因为AnimationSet继承自Animation类所以该方法的参数既可以是动画对象(Animation)也可以是动画集(AnimationSet )对象
0 0
- android 四种动画TranslateAnimation,ScaleAnimation,RotateAnimation,AlphaAnimation
- Android中的动画(AlphaAnimation、RotateAnimation、ScaleAnimation、TranslateAnimation)
- 视图动画:RotateAnimation、TranslateAnimation、ScaleAnimation、AlphaAnimation
- 补间动画TranslateAnimation、ScaleAnimation、AlphaAnimation、RotateAnimation、AnimationSet
- Android各种动画效果ScaleAnimation,AlphaAnimation,TranslateAnimation,RotateAnimation(文章结尾有代码)
- Android补间动画之ScaleAnimation、AlphaAnimation、RotateAnimation、TranslateAnimation、AnimationSet详解
- AnimationSet,AlphaAnimation,RotateAnimation,ScaleAnimation
- ScaleAnimation、RotateAnimation、ScaleAnimation、TranslateAnimation详解
- 【Android动画九章】-RotateAnimation(旋转动画)和ScaleAnimation(尺寸动画)
- Android AlphaAnimation\TranslateAnimation 多组动画循环+单个动画结束后闪烁问题
- Android动画之AlphaAnimation
- Android 比例动画- ScaleAnimation
- Android 动画之ScaleAnimation
- Android动画之ScaleAnimation
- Android 动画 - AlphaAnimation渐变动画
- Android动画之RotateAnimation
- Android动画-RotateAnimation
- Android 移动动画- TranslateAnimation
- 解决函数中返回局部指针变量的问题,加深理解《堆和栈》问题
- ZOJ
- android Tab和ViewPager结合的例子
- android LayoutInflater.inflate()学习
- 我们需要一台计算机两主板一主一副,副板上网浏览信息,主板工作不连网,两板隔离,同显示在一屏幕。
- android 四种动画TranslateAnimation,ScaleAnimation,RotateAnimation,AlphaAnimation
- android Matrix类控制图片 View的移动、缩放、旋转、错切
- SpringMvc整理
- iOS 【关于百度地图大头针标记 选中状态/点击状态 的区别及处理办法】
- android ActionBar自定义标题栏
- Web Service 的工作原理
- android Service(startService bindService)详解以及全面总结
- 数组与字符串的相互转化
- android HorizontalScrollView学习