Skip to content

Commit 23e43f9

Browse files
committed
Update
1 parent 7771afd commit 23e43f9

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,46 @@ startWithMoveTo | 起始点是否使用 moveTo | 用于保证截取
142142

143143
> 矩形边长400dp,起始点在左上角
144144
145+
![](http://ww2.sinaimg.cn/large/005Xtdi2jw1f4bohcxzhqj308c0etwej.jpg)
146+
147+
代码:
148+
149+
``` java
150+
canvas.translate(mViewWidth / 2, mViewHeight / 2); // 平移坐标系
151+
152+
Path path = new Path(); // 创建Path并添加了一个矩形
153+
path.addRect(-200, -200, 200, 200, Path.Direction.CW);
154+
155+
Path dst = new Path(); // 创建用于存储截取后内容的 Path
156+
157+
PathMeasure measure = new PathMeasure(path, false); // 将 Path 与 PathMeasure 关联
158+
159+
// 截取一部分存入dst中,并使用 moveTo 保持截取得到的 Path 第一个点的位置不变
160+
measure.getSegment(200, 600, dst, true);
161+
162+
canvas.drawPath(dst, mDeafultPaint); // 绘制 dst
163+
```
164+
165+
166+
从上图可以看到我们成功到将需要到片段截取了出来,然而当 dst 中有内容时会怎样呢?
167+
168+
``` java
169+
170+
```
171+
172+
从上面的示例可以得到结论:**被截取的 Path 片段会添加到 dst 中,而不是替换 dst 中到内容。**
173+
174+
前面两个例子中 startWithMoveTo 均为 true, 如果设置为false会怎样呢?
175+
176+
从该示例我们又可以得到一条结论:**如果 startWithMoveTo 为 true, 则被截取出来到Path片段保持原状,如果 startWithMoveTo 为 false,则会将截取出来的 Path 片段的起始点移动到 dst 的最后一个点,以保证 dst 的连续性。**
177+
178+
从而我们可以用以下规则来判断 startWithMoveTo 的取值:
179+
180+
取值 | 主要功用
181+
------|------------------
182+
true | 保证截取得到的 Path 片段不会发生形变
183+
false | 保证存储截取片段的 Path(dst) 的连续性
184+
145185
## 总结
146186

147187

0 commit comments

Comments
 (0)