Android Path class

Source: Internet
Author: User

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

moveTodoes not draw and is used only to move the move brush.
Use it in the following ways.

3, LineTo

lineToUsed 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

quadToUsed 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);


5, Cubicto

cubicToThe 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

arcToUsed 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.