说道自定义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
你们能够关注个人微信公众号:「秦子帅」一个有质量、有态度的公众号!