A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© linxy06 中级黑马   /  2015-11-30 20:45  /  740 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

一个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, int pivotYType, float pivotYValue)
float fromX, float toX  X轴方向从开始的大小到结束的大小
float fromY, float toY  Y轴方向从开始的大小到结束的大小
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的位置
(4) TranslateAnimation
public TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue)
fromXType  X轴上开始点相对类型
fromXValue  开始点的值
toXType    X轴上结束点相对类型
toXValue,  结束点的值
Y轴同理
(5) AnimationSet
这是一个动画的集合类,可以设置多个动画一起执行,比较简单,我就不多介绍了

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马