如果您的背景始终为白色,您可以将“橡皮擦”设为白色路径。然后它会使其他行看起来被删除。
编辑:
也许您可以查询用于在触摸事件中绘制路径的所有点,并创建一个自定义类来封装它。然后有一个方法是这样的:
//other code....
MyCustomClass class = new MyCustomClass();
if(class.contains(float x, float y)) {
//...erase line
}
//other code
MyCustomClass
public class MyCustomClass {
private List<PathPoints> pathPoints;
public MyCustomClass(List<PathPoints> points) {
this.pathPoints = points;
}
public boolen contains(float x, float y) {
for(PathPoint point: pathPoints) {
if(x == point.getX() && y == point.getY()) {
return true;
}
return false;
}
}
}
和路径点类
public class PathPoint {
private float x;
private float y;
private int movementType;
public void setX(float x) {
this.x = x;
}
//..all the other getters and setters.
}
然后在您的 onTouch 事件中为每条绘制的路径添加一个新的 PathPoint 到路径点列表中。仅在 Action.UP 中创建新路径点(用户已停止绘制)。
编辑 2:好的,这是另一个想法。为什么不创建自己的自定义路径类,然后将所有这些逻辑添加到该类中。因此,当您绘制路径时,您只需将路径点添加到路径。然后将方法“contains()”添加到您的自定义路径类。这样,它将包含路径上的每个点,无论是移动到、线到、四边形还是其他。所以是这样的:
public class MyPath extends Path {
private List<PathPoint> points;
public MyPath(List<PathPoints> pathPoints) {
this.points = pathPoints;
}
public void addPathPoint(PathPoint pathPoint) {
if(points != null) {
points.add(pathPoint);
}
}
public boolean contains(float x, float y) {
for(PathPoint pathPoint: points) {
if(pathPoint.getX() == x && pathPoint.getY() == y) {
return true;
}
}
return false;
}
}
它的绘图部分应该仍然可以正常工作,因为您没有触摸它。让我知道这个是否奏效。