interpolator里面是五个控制动画动作快慢的参数
AccelerateDecelerateInterpolator,中间加速,两头慢
AccelerateInterpolator:开始慢,然后加速
CycleInterpolator:动画循环播放特定次数,速率改变沿着正弦曲线
DecelerateInterpolator:减速
LinearInterpolator:匀速
三种使用方法
1.使用xml文件
set中有此属性设置
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:shareInterpolator="true">
代码中直接使用这个xml文件
Animation animation = AnimationUtils.loadAnimation(animation.this, R.anim.alpha);
imageView.startAnimation(animation);
2.为所有动画使用一样的interpolator
AnimationSet animationSet = new AnimationSet(true);
animationSet.setInterpolator(new DecelerateInterpolator());
AlphaAnimation alpha = new AlphaAnimation(1.0f, 0.0f);
RotateAnimation rotate = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
animationSet.addAnimation(alpha);
animationSet.addAnimation(rotate);
animationSet.setDuration(10000);
animationSet.setStartOffset(500);
imageView.startAnimation(animationSet);
3.分别为每个动画设置interpolator
AnimationSet animationSet = new AnimationSet(false);
AlphaAnimation alpha = new AlphaAnimation(1.0f, 0.0f);
alpha.setInterpolator(new DecelerateInterpolator());
RotateAnimation rotate = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setInterpolator(new AccelerateInterpolator());
animationSet.addAnimation(alpha);
animationSet.addAnimation(rotate);
animationSet.setDuration(10000);
animationSet.setStartOffset(500);
imageView.startAnimation(animationSet);
代码