Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override onDraw() or draw()?

Tags:

My project is based on surfaceView and up until now I've had all of my rendering in onDraw which I am overriding. All seemed to be OK.

However, I've just updated my SDK and now it gives me an error telling me:

Suspicious method call; should probably call "draw" rather than "onDraw"

Could someone please explain the difference between these two?

I've read some similar questions around the net but I've not found an explanation that I understand.

Thanks

like image 928
Zippy Avatar asked Feb 13 '13 23:02

Zippy


People also ask

Which View method one must override to Customize the drawing of a View android?

The most important step in drawing a custom view is to override the onDraw() method. The parameter to onDraw() is a Canvas object that the view can use to draw itself.

How to draw shapes in android studio?

In order to draw your shape, you must compile the shader code, add them to a OpenGL ES program object and then link the program. Do this in your drawn object's constructor, so it is only done once.

Which method is used to redraw on screen and results to a call of the view onDraw () method?

You can't call onDraw directly. Instead you should call invalidate to tell the view that it needs to redraw itself.

What is canvas drawing in Android?

Canvas API is a drawing framework that is provided in Android, with the help of which we can create custom shapes like rectangle, circle, and many more in our UI design. With the help of this API, we can draw any type of shape for our app. The drawing of the different shapes is done using Bitmap.


1 Answers

I tried cleaning my project and it did solve the problem. Try it.

like image 76
KarenAnne Avatar answered Nov 06 '22 10:11

KarenAnne