获取android中手势绘制的直线的终点

时间:2016-06-18 03:25:02

标签: android gestures

使用android GestureOverlayView我想检测所绘制手势的两个端点。在下图中,我必须检测以圆圈绘制的点。

gesture points

是否可以这样做,或者我使用GestureOverlayView使用了错误的方法?

2 个答案:

答案 0 :(得分:1)

处理此问题的最简单方法是实现View.OnTouchListener

@Override
public boolean onTouch(View v, MotionEvent event)
{
    float x = event.getX();
    float y = event.getY();

    switch(event.getAction())
    {
        case MotionEvent.ACTION_DOWN:
            // A pressed gesture has started, the motion contains the initial starting location.
            break;

        case MotionEvent.ACTION_MOVE:
            // A change has happened during a press gesture (between ACTION_DOWN and ACTION_UP).
            break;

        case MotionEvent.ACTION_UP:
            //  A pressed gesture has finished, the motion contains the final release location
            // as well as any intermediate points since the last down or move event.
            break;

    }
    return false; //True if the listener has consumed the event, false otherwise.
}

答案 1 :(得分:0)

尝试阅读这篇文章http://www.devlper.com/2010/10/gesture-detection-in-android-part-1-of-2/它可能对您有帮助。