Canvas 是 Android 中用于绘制图形的重要类,它提供了许多用于绘制的常用方法。以下是一些常用的 Canvas 方法:
-  绘制颜色和背景: - drawColor(int color): 用指定颜色填充整个画布。
- drawRGB(int r, int g, int b): 用 RGB 值指定颜色填充整个画布。
 
-  绘制基本形状: - drawPoint(float x, float y, Paint paint): 在指定位置绘制点。
- drawLine(float startX, float startY, float stopX, float stopY, Paint paint): 绘制直线。
- drawRect(Rect rect, Paint paint): 绘制矩形。
- drawRoundRect(RectF rect, float rx, float ry, Paint paint): 绘制圆角矩形。
- drawCircle(float cx, float cy, float radius, Paint paint): 绘制圆形。
- drawOval(RectF oval, Paint paint): 绘制椭圆。
 
-  绘制文本: - drawText(String text, float x, float y, Paint paint): 在指定位置绘制文本。
- drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint): 沿路径绘制文本。
 
-  绘制图像: - drawBitmap(Bitmap bitmap, float left, float top, Paint paint): 绘制位图。
- drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint): 绘制位图的一部分到指定区域。
 
-  绘制路径: - drawPath(Path path, Paint paint): 绘制路径。
- clipPath(Path path): 根据指定路径裁剪画布。
 
-  状态保存和恢复: - save(): 保存当前画布的状态。
- restore(): 恢复上一次保存的画布状态。
 
-  绘制效果: - drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint): 绘制圆弧。
- drawBitmapShader(Bitmap bitmap, Shader.TileMode tileX, Shader.TileMode tileY, Paint paint): 使用位图纹理填充图形。
- drawShader(Shader shader, float left, float top, float right, float bottom, Paint paint): 使用着色器填充图形。
 
-  其他: - translate(float dx, float dy): 平移画布。
- rotate(float degrees): 旋转画布。
- scale(float sx, float sy): 缩放画布。
 
这只是 Canvas 类提供的一部分方法,实际上它还有许多其他方法和功能,可以满足不同的绘图需求。根据具体的场景和需求,你可以选择使用适当的方法来完成相应的绘制操作。