boolean getSegment (float startD, float stopD, Path dst, boolean startWithMoveTo)
Given a start and stop distance, return in dst the intervening segment(s). If the segment is zero-length, return false, else return true. startD and stopD are pinned to legal values (0..getLength()). If startD >= stopD then return false (and leave dst untouched). Begin the segment with a moveTo if startWithMoveTo is true.
On KITKAT
and earlier releases, the resulting path may not display on a hardware-accelerated Canvas. A simple workaround is to add a single operation to this path, such asdst.rLineTo(0, 0)
.
以上是官方文档的解释。
在使用该方法时要注意On KITKAT
and earlier releases, the resulting path may not display on a hardware-accelerated Canvas. A simple workaround is to add a single operation to this path, such asdst.rLineTo(0, 0)
.这句话的解释。
这句话的意思是:在android KITKAT版本及之前的版本,该方法所获取到的path是无法被绘制显示出来的。要解决该问题的简单方法就是在所要获取的path上执行lineTo(0, 0) 或执行rLineTo(0, 0);
例子:
public void setDistance(float distance) {
this.distance = distance;
mDstPath.reset();
mDstPath.lineTo(0, 0);
mPathMeasure.getSegment(0, distance, mDstPath, true);
invalidate();
}