Since onDraw can be used to draw a blue background, can we do some bad things? Haha .....
But before doing something bad, remember to learn some knowledge in graphics.
I. Basic preparation knowledge
1. Canvas-Canvas
Canvas is a large Canvas. The size of the Canvas depends on the size of the Canvas supported by the Android system. Later, I will know how big the Canvas is, but in principle: canvas is infinite.
2. Paint-Paint
If there is no Paint board, how can it be done? Yes, Paint is the Paint brush. In charge of all the brushes in the Android kingdom, as long as you deal with Canvas, no paint brush will never work ......
3. Color-Color
In this design world, there is no Color in charge of all kinds of colors, so here we define a variety of commonly used colors, Ga, also provides a flexible Color. parseColor (String str); this function is too powerful. Haha, parse the Alpha color and common color.
4. Bitmap-Bitmap
The world without images is miserable. This class can manage png and jpg images in the world, but it seems that Android supports png better than jpg. In the next study, we will use three methods to obtain images in the Drawable folder.
2. Start graffiti
Are you ready ?? We started graffiti .................
/**
* Draw a View
**/
Protected void onDraw (Canvas canvas ){
Canvas. drawColor (Color. WHITE );
}
Let's draw the canvas in white first, and then use the paint brush .......
/**
* Define a paint brush
**/
Paint paint;
/**
* Initialize the paint brush
**/
Public void intiPaint (){
Paint = new Paint ();
// Set the paint brush
Paint. setColor (Color. GREEN); // GREEN paint brush
Paint. setAntiAlias (true); // enable anti-aliasing
Paint. setTextSize (15); // you can specify the font size.
}
/**
* Draw a View
**/
Protected void onDraw (Canvas canvas ){
Canvas. drawColor (Color. WHITE );
Canvas. drawText ("My first use of paint-movie moon", 20, 20, paint );
}
OK source code download: http://www.bkjia.com/uploadfile/2011/1129/20111129034903929.rar
Author Xing haoyue