1、效果图跟上一遍博客一样,请参考Android动画效果Animation之Tween实现简单动画;
接下来直接java代码实现如何实现动画:
定义
private Animation animation_alpha,animation_scale,animation_translate,animation_rotate;
private AnimationSet animationSet;
分别是透明度动画、旋转动画、尺寸伸缩动画、移动动画
具体实现代码如下:
private void initAnimation() {
//透明度控制动画效果 alpha
animation_alpha=new AlphaAnimation(0.1f,1.0f);
//第一个参数fromAlpha为 动画开始时候透明度
//第二个参数toAlpha为 动画结束时候透明度
animation_alpha.setRepeatCount(-1);//设置循环
animation_alpha.setDuration(5000);//设置时间持续时间为 5000毫秒
// 旋转效果rotate
animation_rotate = new RotateAnimation(0, -720,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
//第一个参数fromDegrees为动画起始时的旋转角度 //第二个参数toDegrees为动画旋转到的角度
//第三个参数pivotXType为动画在X轴相对于物件位置类型 //第四个参数pivotXValue为动画相对于物件的X坐标的开始位置
//第五个参数pivotXType为动画在Y轴相对于物件位置类型 //第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置
animation_rotate.setRepeatCount(-1);
animation_rotate.setDuration(5000);//设置时间持续时间为 5000毫秒
//尺寸伸缩动画效果 scale
animation_scale=new ScaleAnimation(0.1f,3.0f,0.1f,3.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
//第一个参数fromX为动画起始时 X坐标上的伸缩尺寸
//第二个参数toX为动画结束时 X坐标上的伸缩尺寸
//第三个参数fromY为动画起始时Y坐标上的伸缩尺寸
//第四个参数toY为动画结束时Y坐标上的伸缩尺寸
/*说明:
以上四种属性值
0.0表示收缩到没有
1.0表示正常无伸缩
值小于1.0表示收缩
值大于1.0表示放大
*/
//第五个参数pivotXType为动画在X轴相对于物件位置类型
//第六个参数pivotXValue为动画相对于物件的X坐标的开始位置
//第七个参数pivotXType为动画在Y轴相对于物件位置类型
//第八个参数pivotYValue为动画相对于物件的Y坐标的开始位置
animation_scale.setRepeatCount(-1);
animation_scale.setDuration(5000);//设置时间持续时间为 5000毫秒
//移动动画效果translate
animation_translate=new TranslateAnimation(-20f,300f,-20f,300f);
//第一个参数fromXDelta为动画起始时 X坐标上的移动位置
//第二个参数toXDelta为动画结束时 X坐标上的移动位置
//第三个参数fromYDelta为动画起始时Y坐标上的移动位置
//第三个参数toYDelta为动画结束时Y坐标上的移动位置
animation_translate.setRepeatCount(-1);//设置动画执行多少次,如果是-1的话就是一直重复
animation_translate.setDuration(5000);//设置时间持续时间为 5000毫秒
animationSet=new AnimationSet(true);
animationSet.addAnimation(animation_alpha);//透明度
animationSet.addAnimation(animation_rotate);//旋转
animationSet.addAnimation(animation_scale);//尺寸伸缩
animationSet.addAnimation(animation_translate);//移动
image.startAnimation(animationSet);//开始播放
}
AnimationSet这个类是:
Represents a group of Animations that should be played together. The transformation of each individual animation are composed together into a single transform. If AnimationSet sets any properties that its children also set (for example, duration or fillBefore),
the values of AnimationSet override the child values.
意思是:代表一群动画应该一同玩耍。转变是由每个个体的动画在一起,成为一个单一的变换。如果AnimationSet设置任何属性,其子女也设置(例如,持续时间或fillBefore)的值AnimationSet推翻这孩子的价值观。
分享到:
相关推荐
该Demo,主要以xml形式实现了Animation动画中的Tween动画(另一种动画Frame动画Demo,稍后奉上),Tween动画的另一种实现形式是直接在代码中实现,相关Demo已上传,有需要的读者请到我的资源文件中下载即可。
比较全的android动画例子,包括基础的tween animation,这个就不必说了,还有比较新的属性动画:property animation
相关博客见 http://blog.csdn.net/wzg_1987/article/details/8842661
Android TweenAnimation动画源码
Android Tween Animation动画的使用demo,以及自定义动画,原理解析,相关博客: http://blog.csdn.net/w18756901575/article/details/53081551
Android动画之Animation的使用。包括变换动画Tween Animation,帧动画Frame Animation,布局动画Layout Animation,属性动画Property Animation
Android使用TweenAnimation生成动画效果的例程,生成补间动画的例子,是一个比较基础简单的Android动画特效实例。
前面讲了动画中的Frame动画,今天就来详细讲解一下Tween动画的使用。同样,在开始实例演示之前,先引用官方文档中的一段话:Tween动画是操作某个控件让其展现出旋转、渐变、移动、缩放的这么一种转换过程,我们成为...
包含AlphaAnimation渐变效果 TranslateAnimation:位移渐变 ScaleAnimation:缩放渐变 RotateAnimation:旋转渐变 AnimationSet:组合渐变... frameAnimation:帧动画的xml和代码实现方式,非常适合新手朋友参考。
博客示例代码,详情访问:http://blog.csdn.net/xiaohao0724/article/details/54614024
上次提供了Animation动画其一Tween补间动画的源代码,这次提供其二Frame动画的源代码(以直接编码的形式实现Frame动画的Demo,笔者资源中另有以xml形式实现的Demo)。
之前说过了在Android中,动画Animation的实现有两种方式:Tween Animation(渐变动画)和Frame Animation(帧动画)。渐变动画是通过对场景里的对象不断做图像变换(平移、缩放、旋转等)产生动画效果。帧动画则是...
这是Android图形图像之补间动画的一个Demo,希望对您有所帮助。
前面讲了《Android动画之逐帧动画(Frame Animation)》,今天就来详细讲解一下Tween动画的使用。 同样,在开始实例演示之前,先引用官方文档中的一段话: Tween动画是操作某个控件让其展现出旋转、渐变、移动、缩放的...
补间动画包含有scale,rotate,translate,alpha
android 动画 简单使用 property animation view animation(tween animation)drawable animation(frame animation)
主要介绍Android中如何使用rotate实现图片不停旋转的效果。Android 平台提供了两类动画,一类是 Tween 动画,即通过对场景里的对象不断做图像变换(平移、缩放、旋转)产生动画效果;第二类是 Frame 动画,即顺序播放...
本文实例讲述了Android动画之渐变动画(Tween Animation)。分享给大家供大家参考,具体如下: Android 平台提供了两类动画。 一类是Tween动画,就是对场景里的对象不断的进行图像变化来产生动画效果(旋转、平移、...