chossen-addict
chossen-addict

Reputation: 390

Working with canvas and bitmaps in android

I am trying to use Canvas and Bitmaps to draw in my activity, but I am not getting a hold of things like:

  1. When is the onDraw function called.
  2. How can we call onDraw function again after making changes. (this.invalidate does not seem to do the trick).
  3. How to have something drawn on the canvas and make changes to it and later refresh it.

Can someone explain these? (Example code would be an extra plus). Thanks :)

Upvotes: 0

Views: 129

Answers (1)

Mark
Mark

Reputation: 164

  1. onDraw() is initially called by the system sometime after inflating the layout containing the View. If you setContentView() in your onCreate(), for example, you have at least until onCreate() returns before it will be drawn because the UI thread must go idle in order for a draw to occur.

  2. invalidate() is the way to do this. Don't call it from within onDraw or you'll be in an infinite loop.

  3. Again, use invalidate() whenever you need a redraw. That is its purpose.

Upvotes: 1

Related Questions