您的位置:首页 > 移动开发 > Android开发

Android补间动画(TweenedAnimations)详解

2015-11-26 11:11 441 查看

一、直线

// 1、new对象(几种方式)

/**

*参数一fromXDelta(x轴,起始的位置)

*参数二toXDelta(x轴,到达的位置) 参数三四,为y轴

*/

TranslateAnimation animation = new TranslateAnimation(fromXDelta, toXDelta, fromYDelta, toYDelta);

/**

*fromXType    相对运动的类型,一般为Animation.RELATIVE_TO_SELF(相对自己)

*fromXValue   起始位置,这里注意,是倍数关系

*toXType         一般为Animation.RELATIVE_TO_SELF

*toXValue       终点位置,这里注意,是倍数关系

*fromYType       fromYValue     toYType     toYValue

*/

TranslateAnimation animation = new TranslateAnimation(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue);

//2、关键的一些设置
animation.setDuration(3000);// 设置播放时间
animation.setRepeatCount(1);//设置重复的次数
animation.setRepeatMode(Animation.REVERSE  );//设置重复播放的mode
,REVERSE是相反,默认设置是RESTART从头播放一次
animation.setFillAfter(true);//设置动画后保留在终止的位置,这是只是显示位置变了,实际的属性没变(如果有点击事件,要设置setEnabled(false))
//3、start
View.startAnimation(animation);

二、大小(缩放)

// 1、new对象(几种方式)

/**
*fromX   这里是倍数关系,从原来的x(view的宽度)的多少倍开始
*toX       这里是倍数关系,到原来的x(view的宽度)的多少倍结束
*fromY   这里是倍数关系,从原来的y(view的高度)的多少倍开始
*toY       这里是倍数关系,到原来的y(view的宽度)的多少倍结束
*/
ScaleAnimation animation = new ScaleAnimation(fromX, toX, fromY, toY);
/**
*fromX    toX     fromY     toY
*pivotX    缩放的中心位置(相对于左上角x轴的位置),中间的为View.getWidth()/2;
*pivotY    缩放的中心位置(相对于左上角y轴的位置)  , 中间的为View.getHeight()/2;
*/
ScaleAnimation animation = new ScaleAnimation(fromX, toX, fromY, toY, pivotX, pivotY);
/**
*fromX      toX      fromY      toY
*pivotXType  一般为Animation.RELATIVE_TO_SELF
*pivotXValue   这里是倍数,中间的换直接填0.5f
*pivotYType   一般为Animation.RELATIVE_TO_SELF
*pivotYValue  这里是倍数,中间的换直接填0.5f
*/
ScaleAnimation animation = new ScaleAnimation(fromX, toX, fromY, toY, pivotXType, pivotXValue, pivotYType, pivotYValue);
//2、关键的一些设置(同上)

//3、start (同上)

三、透明

// 1、new对象(几种方式)

/**

107b4
*fromAlpha   起始透明度,取值是0~1 (0是完全透明,1是完全不透明)

*toAlpha       终止透明度

*/

AlphaAnimation animation = new AlphaAnimation(fromAlpha, toAlpha);

//2、关键的一些设置(同上)

//3、start (同上)

四、旋转

// 1、new对象(几种方式)

/**   和(缩放)一样的  

*fromDegrees  起始的角度,0~360

*toDegrees       终止的角度,0~360

*/

RotateAnimation animation = new RotateAnimation(fromDegrees, toDegrees);

/**   和(缩放)一样的  

*fromDegrees  起始的角度,0~360

*toDegrees       终止的角度,0~360

*pivotX    旋转的中心位置(相对于左上角x轴的位置),中间的为View.getWidth()/2;
*pivotY    旋转的中心位置(相对于左上角y轴的位置)  , 中间的为View.getHeight()/2;

*/

RotateAnimation animation = new RotateAnimation(fromDegrees, toDegrees, pivotX, pivotY);

/**   和(缩放)一样的  

*fromDegrees  起始的角度,0~360

*toDegrees       终止的角度,0~360

*pivotXType  一般为Animation.RELATIVE_TO_SELF
*pivotXValue   这里是倍数,中间的换直接填0.5f
*pivotYType   一般为Animation.RELATIVE_TO_SELF
*pivotYValue  这里是倍数,中间的换直接填0.5f

*/

RotateAnimation animation = new RotateAnimation(fromDegrees, toDegrees, pivotXType, pivotXValue, pivotYType, pivotYValue);

//2、关键的一些设置(同上)
//3、start (同上)

五、动画一起放

AnimationSet set = new AnimationSet(false); //填false就好

set.addAnimation(animation1);

set.addAnimation(animation2);

set.addAnimation(animation3);

set.addAnimation(animation4);

  iv.startAnimation(set);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息