mini mini - 1 year ago 132
Android Question

View onDraw(Canvas c) versus draw(Canvas c) in android?

I am new to android development, I am exploring about

. I come across to known two methods
onDraw(Canvas c)
draw(Canvas c)

Could please explain me the difference and usage of these two methods? Which method will give better performance(FPS) when updating canvas with images?

Answer Source

There is difference between them

  1. The onDraw(Canvas c) is a override method and automatically called when the view is being rendered. Here you can do your additional drawing like make circles, lines or whatever you want.

  2. The draw(Canvas c) is used to manually render this view (and all of its children) to the given canvas. The view must have already done a full layout before this function is called. When implementing a view, implement onDraw( instead of overriding this method. If you do need to override this method, call the superclass version.

Or in simple words draw(Canvas c) is simply a function that is not automatically called when the view is rendered. User is needed to provide the canvas on which this view will rendered and user also have to do all the drawing on the canvas before calling this function.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download