public class PathEffect extends Object
This class provides constructors for creating multiple path effects, including dashed-line, discrete, rounded-corner, and composed path effects.
| 限定符和类型 | 类 | 说明 |
|---|---|---|
static class |
PathEffect.Style |
Enumerates the permutation styles of each shape in the path effect.
|
| 构造器 | 说明 |
|---|---|
PathEffect(float cornerRadius) |
A constructor used to create a
CornerPathEffect instance. |
PathEffect(float[] intervals,
float phase) |
A constructor used to create a dashed-line effect with the specified
intervals and phase. |
PathEffect(float segLength,
float deviation) |
A constructor used to create a
DiscretePathEffect instance. |
PathEffect(PathEffect outerPathEffect,
PathEffect innerPathEffect) |
A constructor used to create a
ComposePathEffect instance. |
PathEffect(Path shape,
float advance,
float phase,
PathEffect.Style style) |
A constructor used to create a
Path1DPathEffect instance. |
public PathEffect(float[] intervals,
float phase)
intervals and phase.
Values saved in intervals are in pairs: The even and odd indices of these values specify the number
of pixels to draw and the number of blank pixels, respectively. For example, if a line segment starts at
(100, 100) and ends at (400, 100), and if intervals is set to {5.0f, 10.0f, 15.0f, 10.0f, 25.0f, 20.0f}
and phase is set to 10.0f, then the Canvas#drawLine(Point, Point, Paint) method draws
five blank pixels and a 15-pixel solid line segment until all values in the value array intervals are
used for drawing in the same manner.
intervals - Indicates the array of pixels to draw and blank pixels, which are jointly used to create the
dashed-line effect.phase - Indicates the offset from where the pixel starts in intervals.public PathEffect(float cornerRadius)
CornerPathEffect instance.
In this path effect, rounded corners are used to connect line segments of the path in a smoother manner.
cornerRadius - Indicates the radius of the rounded corners on the path.public PathEffect(Path shape, float advance, float phase, PathEffect.Style style)
Path1DPathEffect instance.
The Path1DPathEffect object is similar to DashPathEffect except that Path1DPathEffect
has the dash-line effect produced by a specified shape, such as a circle, rectangle, and triangle. Note that this
effect takes effect only when the style of Paint is STROKE or STROKE_AND_FILL, regardless
of the line width of this Paint.
shape - Indicates the shape on the path.advance - Indicates the distance between two adjacent shapes.phase - Indicates the offset, which is similar to that in DashPathEffect. You can change the value
of this parameter to produce an animation effect.style - Indicates the permutation style of each shape, especially distinct at the corner. For details, see
Style.public PathEffect(float segLength,
float deviation)
DiscretePathEffect instance.
This constructor produces discrete effect on the original path, for example, for rusty iron wires. The shorter the line segment, the greater the line deviation, and the more obvious the "burr" effect.
segLength - Indicates the length of the line segment.deviation - Indicates the deviation from the original position of the line segment.public PathEffect(PathEffect outerPathEffect, PathEffect innerPathEffect)
ComposePathEffect instance.
This constructor combines two path effects to form a composed path effect. Specifically, the
innerPathEffect is added and then the outerPathEffect is appended to innerPathEffect.
outerPathEffect - Indicates the path effect to append to the end of innerPathEffect.innerPathEffect - Indicates the initial path effect to add for the path.