Canvas
- drawColor(@ColorInt int color) 颜色填充
- drawCircle(float centerX, float centerY, float radius, Paint paint) 画圆
- drawPoint(float x, float y,Paint paint) 画点
- drawOval(float left, float top, float right, float bottom, Paint paint) 画椭圆
- drawLine(float startX, float startY, float stopX, float stopY, Paint paint) 画线
- drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint paint) 画圆角矩形
- drawArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle, boolean useCenter, Paint paint) 绘制弧形或扇形
- drawPath(Path path, Paint paint) 画自定义图形
- drawBitmap(Bitmap bitmap, float left, float top, Paint paint) 画 Bitmap
- drawText(String text, float x, float y, Paint paint) 绘制文字
Paint
- paint.setStyle(Paint.Style.STROKE); //默认是 FILL
- paint.setPathEffect(effect);
注意: PathEffect 在有些情况下不支持硬件加速,需要关闭硬件加速才能正常使用:Canvas.drawLine() 和 Canvas.drawLines() 方法画直线时,setPathEffect() 是不支持硬件加速的;PathDashPathEffect 对硬件加速的支持也有问题,所以当使用 PathDashPathEffect 的时候,最好也把硬件加速关了 - paint.setStrokeCap(Paint.Cap.BUTT);//默认 BUTT; ROUND 圆; SQUARE 方
- paint. setStrokeJoin(Paint.Join join)设置拐角的形状。有三个值可以选择:MITER 尖角、 BEVEL 平角和 ROUND 圆角。默认为 MITER
- paint.setShader(),就不用setColor/ARGB() 设置的颜色了
ComposeShader() 在硬件加速下是不支持两个相同类型的 Shader 的,所以这里也需要关闭硬件加速才能看到效果。 - paint. setShadowLayer() 在硬件加速开启的情况下, setShadowLayer() 只支持文字的绘制,文字之外的绘制必须关闭硬件加速才能正常绘制阴影。
- paint.drawText(text, 200, 100, paint) x 和 y 是文字的坐标。但需要注意:这个坐标并不是文字的左上角,而是一个与左下角比较接近的位置。