說道自定義View,咱們必定會想到,自定義View的繪製流程html
咱們看到的一些炫酷的view效果,都是在繪製方法裏去實現的, 也就是draw(Canvas)
, 咱們先放下 測量與佈局, 先從繪製基礎開始學起。android
說到ondraw(Canvas)
方法,不得不提Paint
與Canvas
。咱們先來看Paint
canvas
Paint就是"畫筆",咱們先去看下Paint類的源碼解釋:微信
** * The Paint class holds the style and color information about how to draw * geometries, text and bitmaps. */
Paint類能夠畫幾何圖形,文本與bitmap。 Paint類方法比較多, 這裏拿Paint.Style舉例:佈局
(1).定義 Canvas就是「畫布」,咱們先去看下Canvas類的源碼解釋:google
* 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 (e.g. Rect, * Path, text, Bitmap), and a paint (to describe the colors and styles for the * drawing).
(2).繪製方法3d
方法比較多了,這裏我就隨便舉幾個例子:code
Paint paint=new Paint(); paint.setColor(Color.BLUE); paint.setStrokeWidth(20); paint.setStyle(Paint.Style.FILL); canvas.drawLine(200,200,450,200,paint);
Paint paint=new Paint(); paint.setColor(Color.BLUE); paint.setStrokeWidth(50); paint.setStyle(Paint.Style.FILL ); canvas.drawRect(100,100,200,200,paint);
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);
更多的方法以及方法的含義能夠去下面的API地址去看! API地址component
今天就講到這裏 ,繪製基礎還有一個很是重要的類,Paht(路徑)類,下一節講一下。 但願對你們有所幫助!orm
你們能夠關注個人微信公衆號:「秦子帥」一個有質量、有態度的公衆號!