Custom View entry - drawn basis (1)

### Custom View preface says, we will think, Custom View drawing process - measurement phase (measure) - layout phase (layout) - drawing stage (draw) we saw some of the cool effects of view, are the method is implemented in a draw to go, that is, `draw (Canvas)`, we first lay down measurement and layout, start with the foundation began to learn to draw. ### Detailed Speaking `ondraw (Canvas)` method, we must mention `Paint` and` Canvas`. Let's look at `Paint` ###### 1.Paint Paint is the" brush ", we went to look at the source code Paint class explanation:` `` ** * The Paint class holds the style and color information about how to draw * geometries, text and bitmaps. * / `` `paint class can draw geometric shapes, text and bitmap. Paint more class method, here take Paint.Style example: - Paint.Style.FILL: to fill the inside - Paint.Style.FILL_AND_STROKE: internal filling and stroke - Paint.Style.STROKE:! Stroke [] (https: / /img2018.cnblogs.com/blog/1312938/201909/1312938-20190921160047699-1410664224.png) ###### 2.Canvas ** (1). ** canvas is the definition of "canvas", we went to look Canvas class source explained: `` `* the Canvas class holds the" draw "calls 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 (eg Rect, * Path, text, Bitmap), and a paint (to describe the colors and styles for the * drawing) `` `- bitmap pixel bearer - canvas painting method call hold - described drawing brush colors and styles - the type of drawing. ** (2) ** Draw method method more, and here I will just cite a few examples: - drawing a line `` `Paint paint = new Paint (); paint.setColor (Color.BLUE); paint.setStrokeWidth (20); paint.setStyle (Paint.Style.FILL); canvas.drawLine (200,200,450,200, paint);! `` `[] (https://img2018.cnblogs.com/blog/1312938/201909/1312938-20190921160048089 -269409115.png) - Videos rectangular `` `Paint paint = new Paint (); paint.setColor (Color.BLUE); paint.setStrokeWidth (50); paint.setStyle (Paint.Style.FILL); canvas.drawRect ( 100,100,200,200, paint);! `` `[] (https://img2018.cnblogs.com/blog/1312938/201909/1312938-20190921160048326-68976265.png) - Videos sector -140 °` `` Paint paint = new Paint (); paint.setColor (Color.BLUE); paint.setStrokeWidth (50); paint.setStyle (Paint.Style.FILL); canvas.drawArc (100,100,400,400,0,140, ​​false, paint);! `` `[] (https://img2018.cnblogs.com/blog/ 1312938/201909 / 1312938-20190921160048569-499644571.png) meaning more ways and methods of the API can go to the following address to see! [API Address] (https://developer.android.google.cn/reference/android/graphics/Canvas.html) will stop here today, there is a very important basis for drawing class, ** Paht (path) class **, the next section talk about. I hope to be helpful! We can focus on my micro-channel public number: "Qin Shuai child" a quality, public attitudes numbers! ! [Public number] (https://img2018.cnblogs.com/blog/1312938/201909/1312938-20190921160048726-1254022071.jpg) html) all for today, there is a very important basis for drawing class, ** Paht (path) class **, the next section talk about. I hope to be helpful! We can focus on my micro-channel public number: "Qin Shuai child" a quality, public attitudes numbers! ! [Public number] (https://img2018.cnblogs.com/blog/1312938/201909/1312938-20190921160048726-1254022071.jpg) html) all for today, there is a very important basis for drawing class, ** Paht (path) class **, the next section talk about. I hope to be helpful! We can focus on my micro-channel public number: "Qin Shuai child" a quality, public attitudes numbers! ! [Public number] (https://img2018.cnblogs.com/blog/1312938/201909/1312938-20190921160048726-1254022071.jpg)

Guess you like

Origin www.cnblogs.com/qinzishuai/p/11563423.html