Android 设置绘制对象颜色的动画
我正在尝试在自定义视图中的颜色之间为Android 设置绘制对象颜色的动画,android,animation,android-animation,paint,Android,Animation,Android Animation,Paint,我正在尝试在自定义视图中的颜色之间为绘制对象设置动画。但动画不起作用 ObjectAnimator colorFade = ObjectAnimator.ofObject(mCirclePaint, "color", new ArgbEvaluator(), getColor(), 0xff000000); colorFade.setDuration(1500); colorFade.start(); invali
绘制对象设置动画。但动画不起作用
ObjectAnimator colorFade = ObjectAnimator.ofObject(mCirclePaint, "color", new ArgbEvaluator(), getColor(), 0xff000000);
colorFade.setDuration(1500);
colorFade.start();
invalidate();
我之前将油漆颜色设置如下:
mCirclePaint.setColor(Color.RED)代码>
更新我不认为处理程序
对是否设置动画没有影响。即使没有处理程序,我也无法设置绘制对象的动画。尝试以下操作:
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);
}
}
这就是我找到的解决方案:
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();
什么是mCirclePaint?@pskink它只是一个圆的绘制对象。mCirclePaint已正确设置动画,您的问题是invalidate未正确设置called@pskink我只是有同样的想法,但是我需要在哪里调用invalidate()
?我现在有它,但它显然是在错误的地方。谢谢!我刚刚用一个动画监听器发布了一个答案。我必须在哪里添加这些代码,在onDraw还是在inIt()方法中?