Android Path 类学习

这是 Kevin 的一篇 Google Android API 的翻译习作,原文请移步:

Android Deveolopers Path 类 api


public class
公共类

Path

extends Object
继承 Object

java.lang.Object
   ↳ android.graphics.Path

Class Overview
类 概貌


The Path class encapsulates compound (multiple contour) geometric paths consisting of straight line segments, quadratic curves, and cubic curves. It can be drawn with canvas.drawPath(path, paint), either filled or stroked (based on the paint’s Style), or it can be used for clipping or to draw text on a path.

Path类封装了由直线段,二次曲线,三次曲线混合(多轮廓)组成的几何路径。它可以通过 canvas.drawPath(path, paint) 进行绘制,包括填充和描边(取决于 paint’s Style 这个参数),或者它可以用于裁剪或绘制路径上的文本。

Summary
概要


Nested Classes
嵌套类
enum Path.Direction Specifies how closed shapes (e.g. rects, ovals) are oriented when they are added to a path.
指定封闭的形状(如矩形的,椭圆形),当它们被添加到路径时的方向。有顺时针和逆时针两个数值。
enum Path.FillType Enum for the ways a path may be filled
填充方式的枚举类型:Path.FillType EVEN_ODD,用奇偶规则填充
Path.FillType INVERSE_EVEN_ODD,顾名思义,和EVEN_ODD规则恰好相反。
Path.FillType INVERSE_WINDING,同样,WINDING的反效果。
Path.FillType WINDING,用非零环绕数规则填充。
Public Constructors
公共构造函数
Path()

Create an empty path
创建一个空的 path
Path(Path src)

Create a new path, copying the contents from the src path.
复制 Path src 到一个新的 path
Public Methods
公共类
void addArc(RectF oval, float startAngle, float sweepAngle)

Add the specified arc to the path as a new contour.
将一个指定的弧形作为新的轮廓添加到 path
void addCircle(float x, float y, float radius, Path.Direction dir)

Add a closed circle contour to the path
添加一个闭合圆形轮廓到 path
void addOval(RectF oval, Path.Direction dir)

Add a closed oval contour to the path
添加一个闭合的椭圆形轮廓到 path
void addPath(Path src, float dx, float dy)

Add a copy of src to the path, offset by (dx,dy)
将源 path 拷贝一份并添加到  path(当前),dx, dy 为偏移
void addPath(Path src)

Add a copy of src to the path
将源 path 拷贝一份并添加到  path(当前)
void addPath(Path src, Matrix matrix)

Add a copy of src to the path, transformed by matrix
将源 path 拷贝一份并添加到  path(当前),由 matrix 进行转换
void addRect(float left, float top, float right, float bottom, Path.Direction dir)

Add a closed rectangle contour to the path
添加一个闭合的矩形轮廓到 path
void addRect(RectF rect, Path.Direction dir)

Add a closed rectangle contour to the path
添加一个闭合的矩形轮廓到 path
void addRoundRect(RectF rect, float[] radii, Path.Direction dir)

Add a closed round-rectangle contour to the path.
添加一个闭合的圆角矩形轮廓到 path
void addRoundRect(RectF rect, float rx, float ry, Path.Direction dir)

Add a closed round-rectangle contour to the path
添加一个闭合的圆角矩形轮廓到 path
void arcTo(RectF oval, float startAngle, float sweepAngle)

Append the specified arc to the path as a new contour.
追加指定的弧形到 path 作为一个新的轮廓
void arcTo(RectF oval, float startAngle, float sweepAngle, boolean forceMoveTo)

Append the specified arc to the path as a new contour.
追加指定的弧形到 path 作为一个新的轮廓
void close()

Close the current contour.
闭合当前轮廓
void computeBounds(RectF bounds, boolean exact)

Compute the bounds of the control points of the path, and write the answer into bounds.
计算路径的控制点的边界,并把答案写进边界
void cubicTo(float x1, float y1, float x2, float y2, float x3, float y3)

Add a cubic bezier from the last point, approaching control points (x1,y1) and (x2,y2), and ending at (x3,y3).
从上一个点添加一个三次贝塞尔曲线,经过控制点(x1, y1), (x2, y2),在(x3, y3) 结束
Path.FillType getFillType()

Return the path’s fill type.
返回 path 的填充类型
void incReserve(int extraPtCount)

Hint to the path to prepare for adding more points.
对 path 暗示将会添加更多的点
boolean isEmpty()

Returns true if the path is empty (contains no lines or curves)
当 path 为空时返回 true (包括没有线和曲线)
boolean isInverseFillType()

Returns true if the filltype is one of the INVERSE variants
如果填充类型为 INVERSE 变量的其中一种,返回 true
boolean isRect(RectF rect)

Returns true if the path specifies a rectangle.
如果 path 指定一个矩形,返回 true
void lineTo(float x, float y)

Add a line from the last point to the specified point (x,y).
从上一点到 (x, y) 画线
void moveTo(float x, float y)

Set the beginning of the next contour to the point (x,y).
将下一个轮廓的起点设置为 (x, y)
void offset(float dx, float dy, Path dst)

Offset the path by (dx,dy), returning true on success
<