我正在 android canvas 中绘制路径。这工作正常。现在我想检测何时在屏幕上做出滑动手势是否是在绘制的路径上做出的。我正在使用手势监听器来检测 FlingMovement。
private class GestureListener extends GestureDetector.SimpleOnGestureListener {
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY)
{
try
{
if (Math.abs(e1.getX() - e2.getX()) > SWIPE_MAX_OFF_PATH){
return false;
}
if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
{
//Here find whether the swipe occured on any of the paths drawn in canvas
}
}
catch(Exception e)
{
}
return true;
}
}
在 FlingMovement 中,我将获得滑动的起点和终点。然后我需要检查这些点形成的线是否与画布中绘制的任何路径相交。我怎样才能做到这一点?