Skip to content

Commit ffe114f

Browse files
committed
Update
1 parent eecbd4c commit ffe114f

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

‎CustomView/Advance/[8]Path_Play.md‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,22 @@ startWithMoveTo | 起始点是否使用 moveTo | 用于保证截取
169169
从上图可以看到我们成功到将需要到片段截取了出来,然而当 dst 中有内容时会怎样呢?
170170

171171
``` java
172+
canvas.translate(mViewWidth / 2, mViewHeight / 2); // 平移坐标系
173+
174+
Path path = new Path(); // 创建Path并添加了一个矩形
175+
path.addRect(-200, -200, 200, 200, Path.Direction.CW);
176+
177+
Path dst = new Path(); // 创建用于存储截取后内容的 Path
178+
dst.lineTo(-300, -300); // 在 dst 中添加一条线段
179+
180+
PathMeasure measure = new PathMeasure(path, false); // 将 Path 与 PathMeasure 关联
181+
182+
measure.getSegment(200, 600, dst, true); // 截取一部分 并使用 moveTo 保持截取得到的 Path 第一个点的位置不变
172183

184+
canvas.drawPath(dst, mDeafultPaint); // 绘制 Path
173185
```
174186

175-
从上面的示例可以得到结论:**被截取的 Path 片段会添加到 dst 中,而不是替换 dst 中到内容。**
187+
从上面的示例可以看到 dst 中的线段保留了下来,可以得到结论:**被截取的 Path 片段会添加到 dst 中,而不是替换 dst 中到内容。**
176188

177189
前面两个例子中 startWithMoveTo 均为 true, 如果设置为false会怎样呢?
178190

0 commit comments

Comments
 (0)