Reputation: 11790
I have a custom view. I override the onDraw method to draw a filled circle, among other things. I want the circle to flash between red and blue, the interval can be 100 milliseconds. How would I accomplish such animation? So far I have
@Override
protected void onDraw(Canvas canvas) {
this.mFilledPaint.setColor(Color.BLUE);
canvas.drawCircle(x, y, radius, mFilledPaint);
}
Upvotes: 1
Views: 2498
Reputation: 11357
int color = Color.BLUE;
postDelayed(new Runnable() {
@Override
public void run() {
color = (color == Color.BLUE) ? Color.Black : Color.BLUE;
invalidate();
postDelayed(this, 100);
}
}, 100);
@Override
protected void onDraw(Canvas canvas) {
this.mFilledPaint.setColor(color);
canvas.drawCircle(x, y, radius, mFilledPaint);
}
Call the post delayed in the constructor or nay other function you feel relevant.
Upvotes: 2