Animation与Interpolator及AnimationSet的用法

、动作有很多种,AlphaAnimation, AnimationSet, RotateAnimation, ScaleAnimation, TranslateAnimation
例子:
TranslateAnimation ta = new TranslateAnimation( 2, 200, 2, 2);
// 位置由 [2,2] 到 [200,2]移动
imgView.setAnimation( ta );
ta.setDuration( 2000 );
// 设置 持续时间为2秒
//ta.setStartTime( 1000 );
// 设置1秒后启动
ta.setInterpolator( new AccelerateInterpolator((float) 0.2) );

、动作特效:
Interpolator 定义了动画的变化速度,可以实现匀速、正加速、负加速、无规则变加速等;
Interpolator 是基类,封装了所有 Interpolator 的共同方法,它只有一个方法,即 getInterpolation (float input),该方法 maps a point on the timeline to a multiplier to be applied to the transformations of an animation.

AccelerateDecelerateInterpolator, AccelerateInterpolator, CycleInterpolator, DecelerateInterpolator, LinearInterpolator
AccelerateDecelerateInterpolator,延迟减速,在动作执行到中间的时候才执行该特效。An interpolator where the rate of change starts and ends slowly but accelerates through the middle.
AccelerateInterpolator, 会使慢慢以(float)的参数降低速度。An interpolator where the rate of change starts out slowly and and then accelerates.
LinearInterpolator,平稳不变的,An interpolator where the rate of change is constant。
DecelerateInterpolator,在中间加速,两头慢,An interpolator where the rate of change starts out quickly and and then decelerates.
CycleInterpolator,曲线运动特效,要传递float型的参数。Repeats the animation for a specified number of cycles. The rate of change follows a sinusoidal pattern.

//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等,它包含的子动作也设定了的话,
子动作中的设定将会给覆盖掉。
If AnimationSet sets any properties that its children also set (for example, duration
or fillBefore), the values of AnimationSet override the child values.

AnimationSet as = new AnimationSet( true );
as.addAnimation( ta );
TranslateAnimation t1 = new TranslateAnimation( 2, 200, 8, 300);
t1.setDuration( 2000 );
as.addAnimation( t1 );
RotateAnimation r1 = new RotateAnimation( (float) 1, (float) 0.1 );
r1.setDuration( 2000 );
//as.addAnimation( r1 );
imgView.setAnimation(as);
//as.setDuration( 6000 );
//as.setStartTime( 1000 );
as.start();

你可能感兴趣的:(animation,float,properties,input)