一个Tween动画将对于View对象的内容进行一系列简单的转换,在animation提供了所以关于Tween动画的类,主要有四个常用的类,AlphaAnimation(透明度渐变),RotateAnimation(旋转动画),ScaleAnimation(图片缩放动画),TranslateAnimation(移动动画),AnimationSet(一个动画的集合类),以下是对常用动画特效类的构造方法的作用和参数进行讲解
(1) AlphaAnimation
public AlphaAnimation(float fromAlpha, float toAlpha)
fromAlpha - 开始时候的透明度,其中1表示完全不透明,0表示完全透明的
toAlpha 结束时候的透明度
setDuration(long durationMillis) 设置动画执行的时间
setFillAfter(boolean fillAfter) 设置为true时,动画停在执行完后的效果,默认是执行完动画回到刚开始的效果
setRepeatCount(int repeatCount) 设置动画重复次数,repeatCount默认为0,即执行一次,为1时,即执行2次
setRepeatMode(int repeatMode) 设置动画重复的模式,有Animation.REVERSE和Animation.RESTART两种方式,默认为Animation.RESTART,Animation.RESTART的意思就是说比如你设置重复次数为1,当执行完第一次动画之后,回到动画开始然后执行第二次动画,而你设置Animation.REVERSE时候,比如你动画是从不透明----->透明,执行完第一次动画的时候,变为不透明,然后执行第二次动画,他就从不透明到透明,不知道大家理解我的意思了没?
我就介绍几个常用的方法,其他的动画也有上面的那些方法,然后等下介绍setInterpolator(Interpolator)方法
(2) RotateAnimation
public RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
fromDegrees 动画开始的角度
toDegrees 动画结束的角度
pivotXValue, pivotYValue 绕着旋转的中心点的X坐标和Y坐标
pivotXType, pivotYType 旋转中心点的的相对关系类型,有三种animation.absolute,animation.relative_to_self,或animation.relative_to_parent,animation.absolute绝对坐标类型,也就是相对O点的位置,animation.relative_to_self相对自己,自己视图的左上角那个点为O点位置, animation.relative_to_parent相对父视图左上角那个点为O点位置,即自己View所在的ViewGroup的位置
(3) ScaleAnimation
public ScaleAnimation(float fromX, float toX, float fromY, float toY, int pivotXType, float pivotXValue,