Android SurfaceView onDraw Question

My SurfaceView onDraw method draw LinkedList paths defined by TouchEvents on the screen. I want to add a cancel function that removes the last node path from a LinkedList. When the button is pressed, the path is removed from the list, but SurfaceView is not updated until I delete the cancel button again or touch the screen.

Thanks Eric

+4
source share
2 answers

OnDraw is called every 60 ms in the stream, but it does not update there, which bothers me.

you should use:

postInvalidate(); 

not

 invalidate(); 

postInvalidate(); indicates that the main UI thread is redrawing at the next convenient time. The way you do this will not work in a separate thread.

+3
source

This is because the views are updated only when onDraw () is called, which is due to screen activity (for example, you touch it) or when it does this programmatically.

You want to force: use the invalidate () method inherited from View.

If the deletion happens inside you SurfaceView, just write invalidate () AFTER you finish the deletion. If this happens outside, then just do surfaceViewInstance.invalidate ().

Hope this helps

0
source

All Articles