Question

I refer many sites and also the documentation of Android,but i still having confusion on that,

is onDraw() method is necessary in both View and SurfaceView.

Can some one explains me that how to draw any thing in View and SurfaceView when using onDraw() and without using onDraw() method ?

Thank you.

Was it helpful?

Solution

In SurfaceView is not necessary, in View it is because is your chance to get a reference to the canvas, so you can add extra shapes/Bitmaps to the view, however surface view has a powerful complementary class, SurfaceHolder which has a lockCanvas method that returns a reference to the canvas of the surface view (without having to override onDraw) and most importantly, using lockCanvas you can do all the drawing and processing of your shapes/bitmaps ASYNCHRONOUSLY(with unlockCanvasAndPost to publish your changes), unlike onDraw which depends on the main thread and invalidation of the view to be executed...

Hope it helps.

Regards

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top