Jun 2, 2011

Redraw canvas in Android

Hey all,

this post is quite unrelated to every other in this blog.
I was playing around a bit with OpenGL and Android canvas drawing.

I faced a little problem while updating the canvas.

So I had a view like this:


class MyView extends View {
   @Override
   protected void onDraw(Canvas canvas) {
    canvas.draw(SOME_FANCY_THINGS);
   }
}

I wanted to update my canvas on the screen. Some of you maybe think of: save your canvas from the creation and recall the method from outside: won't work.

You actually have to call invalidate(); on your view object.

class MyView extends View {
   @Override
   protected void onDraw(Canvas canvas) {
    canvas.draw(SOME_FANCY_THINGS);
   }

   protected void reDraw() {
    this.invalidate();
   }

}

I didn't know that. So if you are reading this, you know what to do ;)

Greetz from Germany!

No comments:

Post a Comment