1

Androidキャンバスでパスを描いています。これはうまくいきます。今、スワイプジェスチャが描画されたパス上で行われたかどうかを画面上で検出したいと考えています。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 内で、スワイプの開始点と終了点を取得します。次に、これらの点によって形成された線がキャンバスに描かれたパスと交差するかどうかを確認する必要があります。これどうやってするの?

4

2 に答える 2