Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
With Android, we can display images such as PNG and JPG graphics, as well as text and primitive shapes to the screen. We can paint these items with various colors, styles, or gradients and modify them using standard image transforms. We can even animate objects to give the illusion of motion.
Many of the code examples provided in this chapter are taken from the SimpleDrawing application. This source code for the SimpleDrawing application is provided for download on the book’s websites.
To draw to the screen, you need a valid Canvas object. Typically, we get a valid Canvas object by extending the View class for our own purposes and implementing the onDraw() method.
For example, here’s a simple View subclass called ViewWithRedDot. We override the onDraw() method to dictate what the View looks like; in this case, it draws a red circle on a black background.