How Android view draws

The above mentioned Android how to measure, but a beautiful control, I only know where you grow, of course not. Simply override the OnDraw method and call the colorful brush on the canvas object to draw the "sexy" appearance of the control. So how is view drawn?

To understand how view draws, you need to understand what canvas is? What can paint do.

I. canvas means a canvas on which you can draw what you miss so much. When we override the OnDraw method, we can get a canvas object, which is your stage and draw what you think. On the code.

When you need to redraw a certain control, we only need to call the canvas.drawxxx method on this big stage to draw various graphics.

II. Paint is a brush that can be freely used on the canvas. To draw a picture, you have to adjust the brush. After the brush is adjusted, draw the image on the canvas so that it can be displayed on the mobile phone screen. There are many attributes and methods available on paint to set the brush.

1. Setantialias: sets the aliasing effect of the brush. 2. SetColor: sets the brush color. 3. Setargb: sets the A, R, P, g values of the brush. 4. Setalpha: set alpha value 5. Settextsize: set font size. 6. Setstyle: set brush style, hollow or solid. 7. Setstrokewidth: sets the width of the empty border. 8. Getcolor: get the color of the brush. 9. Getalpha: get the alpha value of the brush.

Now that we know the brush and canvas, let's take a short and concise example to see how the canvas and brush work together to produce a desired figure. As usual, code:

In the above code, we have done the following things:

I. using the knowledge of the previous article, we rewrite the onmeasure method to make this simple custom control wrap adaptively_ Content attribute.

II. We called the OnDraw method, got canvas and paint, and wrote "China" on the view.

The final operation effect is:

This is my insight on how to draw Android view. I hope you can make more suggestions.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>