android将path拆分为多个path

来源:互联网 发布:js数组指定下标截取 编辑:程序博客网 时间:2024/06/08 03:18

在android开发中,我们有时会采用如下api来生成一个Path对象:

Path path = new Path();path.addPath(firstPath);path.addPath(secondPath);

后期我们想将该path拆分为多个path,可以采用如下方法:

ArrayList<Path> list = new ArrayList<Path>();PathMeasure pm = new PathMeasure(path, true);float segment = 0;Path tempPath;do {    tempPath = new Path();    tempPath.rewind();    pm.getSegment(segment, segment + pm.getLength(), tempPath, true);    segment += pm.getLength();    tempPath.close();    list.add(tempPath);} while (pm.nextContour());

上述代码返回的list即为我们之前添加到path中的各个Path对象的集合。

原创粉丝点击