开发者

onDraw() efficient design for a custom view

I have a custom view that represents simple gameboard with several tiles. I have a 2-d array that stores the currently displayed image (0 for no image) for a tile.

Currently within my onDraw() method I loop through the array and display the images for the tiles. However the only time I invoke invalidate() without any args is when开发者_如何学JAVA I reset the board. In all other places I only invoke an invalidate(Rect) for the required tile that needs to be updated.

Is this above implementation of onDraw() in-efficiently drawing the view? If so what would be a better way to do this? (also does invoking invalidate(Rect) guarantee updating only the 'Rect' region OR is this just a recommendation to Android that may be ignored?).

Appreciate any clarifications with this.


Is this above implementation of onDraw() in-efficiently drawing the view?

It is good enough. Otherwise you'd like to learn OpenGL to make use of hardware acceleration in your drawings, but all of this depends on if your tiles are changing every frame or how many tiles you have.

also does invoking invalidate(Rect) guarantee updating only the 'Rect' region OR is this just a recommendation to Android that may be ignored?

It updates the Rect area, infact Romain Guy uses invalidate(Rect) for the default home launcher application in order to not update the whole screen everytime the home screen needs an update.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜