Paint对象的动画颜色

时间:2013-11-10 13:10:48

标签: android animation android-animation paint

我正在尝试在颜色之间的自定义视图中设置Paint对象的动画。但动画无效。

ObjectAnimator colorFade = ObjectAnimator.ofObject(mCirclePaint, "color", new ArgbEvaluator(), getColor(), 0xff000000);
              colorFade.setDuration(1500);
              colorFade.start();

            invalidate();

我之前已将油漆颜色设置为:

mCirclePaint.setColor(Color.RED);

更新我不认为Handler会对动画是否有效产生影响。即使没有处理程序,我也无法为绘画对象制作动画。

2 个答案:

答案 0 :(得分:4)

这是我找到的解决方案:

ObjectAnimator    colorFade = ObjectAnimator.ofObject(mCirclePaint, "color", new ArgbEvaluator(), getColor(), mColors[randomNum]);
                  colorFade.setDuration(1500);
                colorFade.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        // TODO Auto-generated method stub
                        invalidate();

                    }


                });

                  colorFade.start();

答案 1 :(得分:3)

试试这个:

class MyView extends View {
    private Paint mPaint;
    public MyView(Context context) {
        super(context);
        mPaint = new Paint();

        ArgbEvaluator evaluator = new ArgbEvaluator();
        ObjectAnimator animator = ObjectAnimator.ofObject(this, "color", evaluator, 0xffff0000, 0xff00ff00, 0xff0000ff);
        animator.setDuration(6000).start();
    }

    public void setColor(int color) {
        mPaint.setColor(color);
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawPaint(mPaint);
    }
}