Usually, when we try to draw 2D graphics, as android developer page say, we have two ways to choose:
- Draw your graphics or animations into a View object from your layout.
- Draw your graphics directly to a Canvas.
Draw graphics directly to a Canvas is a little bit complicated. You can go to the android developer page for farther details. The following example will show you how to draw a bitmap on the canvas, when you click the canvas.
As android dev guide says, when you’re writing an application in which you would like to perform specialized drawing and/or control the animation of graphics, you should do so by drawing through a Canvas. When we do so, we will put our drawing code in onDrwa() callback method, and Canvas will be pass from the function parameter. And we also can get a canvas by calling SurfaceHolder.lockCanvas();
Here is a code example, apk file and source code:
Android Canvas Example
Hopeful, it will be helpful.