Research on Android custom View (2) -- basic knowledge of plotting

Source: Internet
Author: User

 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.