自定义动画view

基本思路:

使用ValueAnimator类,根据不断变化的因子值,不断修改某个属性值。然后invalidate(重新绘制)。在

onDraw中进行绘制,由于属性值在不断变化,所以呈现出了动画效果。

1.新建ValueAnimator
final ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);//起始位置在最低点
animator.setDuration(1000).setRepeatCount(
0);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
//属性根据animation.getAnimatedValue()进行改变
invalidate();
}
});

2.设置插值器
有匀速,加速等效果。
animator.setInterpolator(new LinearInterpolator());// 匀速旋转

3.设置动画集合,开始动画
这里可以设置多个动画,并且按一定顺序排列。
AnimatorSet animSet = new AnimatorSet();
animSet.play(animator).before(animator1).before(animator2);

    animSet.start();

你可能感兴趣的:(自定义动画view)