1. Why
Because you need to write a custom calendar control yourself, you need to understand some of the underlying classes of Android graphics.
This article focuses on the API for the path class.
2 , MoveTo
moveTo
does not draw and is used only to move the move brush.
Use it in the following ways.
3, LineTo
lineTo
Used for line drawing.
The default is drawn starting at coordinates (0,0).
Did we not say that we moveTo
used to move the brushes?
mPath.moveTo(100, 100);mPath.lineTo(300, 300);canvas.drawPath(mPath, mPaint);
Move the Brush (100,100) at the beginning of the drawing, the effect
An API similar to this is:
Rlineto (int width, int height):
Relative to the original point, the moving distance.
Width:line the horizontal distance of the end point relative to the starting point
The vertical distance of the height:line end point relative to the starting point
4, Quadto
quadTo
Used to draw a smooth curve, that is, a Bezier curve.
mPath.quadTo(x1, y1, x2, y2)
(X1,Y1) is the control point, (X2,y2) is the end point.
In the same way, we need moveTo
to help control.
mPath.moveTo(100, 500);mPath.quadTo(300, 100, 600, 500);canvas.drawPath(mPath, mPaint);
Effect
5, Cubicto
cubicTo
The same is used to achieve Bezier curves.
mPath.cubicTo(x1, y1, x2, y2, x3, y3)
(X1,Y1) is the control point, (X2,y2) is the control point, (X3,Y3) is the end point.
So, cubicTo
quadTo
What's the difference?
This is what the authorities say:
Same as Cubicto, but the coordinates is considered relative to the current point in this contour.
To be blunt, it is a control point.
Then we want to draw the same curve as the previous one, how should we write it?
mPath.moveTo(100, 500);mPath.cubicTo(100, 500, 300, 100, 600, 500);
Look at the effect: exactly the same! What if we don't add moveTo
it?
(0,0) is the starting point, (100,500) and (300,100) the Bezier curve is drawn for the control points:
6, ArcTo
arcTo
Used to draw an arc (actually a part of a circle or ellipse). mPath.arcTo(ovalRectF, startAngle, sweepAngle)
, the ovalRectF
rectangle for the ellipse, the startAngle
starting angle, and the sweepAngle
end angle.
mRectF = new RectF(10, 10, 600, 600);mPath.arcTo(mRectF, 0, 90);canvas.drawPath(mPath, mPaint);
Because of the new RectF(10, 10, 600, 600)
square and intercept 0 ~ 90 度
, the resulting curve is a one-fourth-circle arc. Effect
Android Path class