开发者

Android SurfaceView onDraw Question

My SurfaceView's onDraw method draw's a LinkedList of paths determined by TouchEvents on the screen. I want add an undo feature that removes the last path node from the LinkedList. When the button is hit, the path is removed from th开发者_C百科e list but the SurfaceView doesn't update until I either hit the undo button again or touch the screen.

Thanks, Eric


OnDraw is called every 60 ms in a thread but it isn't updating there which confuses me.

you should be using:

postInvalidate();

not

invalidate();

postInvalidate(); tells the main UI thread to redraw on its next convenient time. The way you are doing it will not work on a seperate thread.


That's because Views are only updated when onDraw() is called, which happens due to screen activity (like you touching it) or when it's programatically forced to do so.

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

If the removal happens inside you SurfaceView, just write invalidate() AFTER you're done removing. If it happens outside, then just do surfaceViewInstance.invalidate().

Hope this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜