Animation与Interpolator及AnimationSet的用法

animation float properties input
、动作有很多种,AlphaAnimation,AnimationSet,RotateAnimation,ScaleAnimation,TranslateAnimation

例子:
TranslateAnimationta=newTranslateAnimation(2,200,2,2);
//位置由[2,2]到[200,2]移动
imgView.setAnimation(ta);
ta.setDuration(2000);
//设置持续时间为2秒
//ta.setStartTime(1000);
//设置1秒后启动
ta.setInterpolator(newAccelerateInterpolator((float)0.2));

、动作特效:
Interpolator定义了动画的变化速度,可以实现匀速、正加速、负加速、无规则变加速等;
Interpolator是基类,封装了所有Interpolator的共同方法,它只有一个方法,即getInterpolation(floatinput),该方法mapsapointonthetimelinetoamultipliertobeappliedtothetransformationsofananimation.

AccelerateDecelerateInterpolator,AccelerateInterpolator,CycleInterpolator,DecelerateInterpolator,LinearInterpolator
AccelerateDecelerateInterpolator,延迟减速,在动作执行到中间的时候才执行该特效。Aninterpolatorwheretherateofchangestartsandendsslowlybutacceleratesthroughthemiddle.
AccelerateInterpolator,会使慢慢以(float)的参数降低速度。Aninterpolatorwheretherateofchangestartsoutslowlyandandthenaccelerates.
LinearInterpolator,平稳不变的,Aninterpolatorwheretherateofchangeisconstant。
DecelerateInterpolator,在中间加速,两头慢,Aninterpolatorwheretherateofchangestartsoutquicklyandandthendecelerates.
CycleInterpolator,曲线运动特效,要传递float型的参数。Repeatstheanimationforaspecifiednumberofcycles.Therateofchangefollowsasinusoidalpattern.

//ta.setRepeatMode(Animation.REVERSE);
ta.setRepeatCount(0);

、setRepeatMode参数应是Animation.RESTART或Animation.REVERSE或Animation.INFINITE,
设置动作结束后,将怎样处理,默认是Animation.RESTART,回到动作开始时的坐标
setRepeatCount(repeatCount),参数是Animation.INFINITE则表示不断重复该动作,
只有在repeatCount大于0或为INFINITE的时候setRepeatMode才会生效。
REVERSE是反转的意思,如果repeatCount大于1,repeatMode为Animation.REVERSE
那么动作将会回来不断执行,即由a点去到b点后,会从b点和原来的动作相反的相同时
间回到a点,依此类推,即是说REVERSE也算入repeatCount。

、AnimationSet可以包含多个Animation,但都是在同一个时间执行的,是并行,不是串行执行的。
如果AnimationSet中有一些设定,如duration,fillBefore等,它包含的子动作也设定了的话,
子动作中的设定将会给覆盖掉。
IfAnimationSetsetsanypropertiesthatitschildrenalsoset(forexample,duration
orfillBefore),thevaluesofAnimationSetoverridethechildvalues.

AnimationSetas=newAnimationSet(true);
as.addAnimation(ta);
TranslateAnimationt1=newTranslateAnimation(2,200,8,300);
t1.setDuration(2000);
as.addAnimation(t1);
RotateAnimationr1=newRotateAnimation((float)1,(float)0.1);
r1.setDuration(2000);
//as.addAnimation(r1);
imgView.setAnimation(as);
//as.setDuration(6000);
//as.setStartTime(1000);
as.start();

转载:http://blog.csdn.net/hb_zha/article/details/7085572