The Android framework APIs provides a set of 2D-drawing APIs that
allow you to render your own custom graphics onto a canvas or to modify
existing Views to customize their look and feel. When drawing 2D
graphics, you'll typically do so in one of two ways:
Option "b," drawing to a Canvas, is better when your application needs to regularly re-draw itself. Applications such as video games should be drawing to the Canvas on its own. However, there's more than one way to do this:
- Draw your graphics or animations into a View object from your layout. In this manner, the drawing of your graphics is handled by the system's normal View hierarchy drawing process — you simply define the graphics to go inside the View.
- Draw your graphics directly to a Canvas. This way, you personally call the appropriate class's
onDraw()method (passing it your Canvas), or one of the Canvasdraw...()methods (like). In doing so, you are also in control of any animation.drawPicture()
Option "b," drawing to a Canvas, is better when your application needs to regularly re-draw itself. Applications such as video games should be drawing to the Canvas on its own. However, there's more than one way to do this:
- In the same thread as your UI Activity, wherein you create a custom View component in your layout, call
and then handle theinvalidate()callback.onDraw() - Or, in a separate thread, wherein you manage a
SurfaceViewand perform draws to the Canvas as fast as your thread is capable (you do not need to requestinvalidate()).
No comments:
Post a Comment