Summary of some operational methods in the custom control-onDraw callback in Android

onDraw is the most commonly used drawing method. The input parameter of this method is the Canvas canvas object. Canvas provides three types of methods, which are the control operations of delimiting the drawable area, drawing graphics inside the area, and the canvas.

1. Delimit the drawable area

  • clipPath: Clip the irregular curve area.
  • clipRect: Clip the rectangular area.
  • clipRegion: crop a combined area.

2. Draw graphics inside the area

  • drawArc: draw a fan/arc. When the fourth parameter is true, a fan is drawn, and when it is false, an arc is drawn.
  • drawBitmap: draw an image.
  • drawCricle: draw a circle.
  • drawLine: draw a straight line.
  • drawOval: Draw an ellipse.
  • drawPath: Draw a path, that is, an irregular curve.
  • drawPoint: draw a point.
  • drawRect: draw a rectangle.
  • drawRoundRect: draw a rounded rectangle.
  • drawText: draw text.

3. Canvas control operation

  • rotate: Rotate the canvas.
  • scale: Scale the canvas.
  • translate: translate the canvas.
  • save: Save the canvas state.
  • restore: restore the canvas state.

4. Paint class related methods

  • setAntiAlias: Set whether to use anti-aliasing function. Mainly used to draw circles and other curves.
  • setDither: Set whether to use the anti-jitter function.
  • setColor: Set the color of the brush.
  • setShadowLayer: Set the shadow area and color of the brush.
  • setStyle: Set the style of the brush. Style.STROKE means line, Style.FILL means fill.
  • setStrokeWidth: Set the width of the brush line.

Guess you like

Origin blog.csdn.net/weixin_38322371/article/details/113687335