Graphical applications, such as games, need a more flexible mechanism so that elements may be freely placed anywhere on screen, and animated by changing their position. The solution is to create a programmatic layout by extending the View class.
public class graphicLayout extends View
{
}
On every frame, the onDraw() method of the View class is called. It receives a parameter of type Canvas, which represents the device's screen area. Override this method to draw the shapes required by your app, by calling the method on Canvas for the particular shape primitive you wish to draw:protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint rectStyle = new Paint();
rectStyle.setColor(Color.BLUE);
canvas.drawRect(new Rect(10, 10, 30, 20), rectStyle);
}
The android developer documentation puts it like this: "To draw something, you need 4 basic components: A Bitmap to hold the pixels, a Canvas to host the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, Path, text, Bitmap), and a Paint (to describe the colours and styles for the drawing)".