Android以编程方式进行多点触控(不是多点触控屏幕上多于一根手指)

时间:2015-02-09 00:34:00

标签: android touch

我想知道一次触摸是否可以进行多次触摸。 就像用鼠标一键式点击一样。

提前致谢

1 个答案:

答案 0 :(得分:0)

您需要使用GestureDetector来检测双击。见这个例子:

 public class MyView extends View {
GestureDetector gestureDetector;

public MyView(Context context, AttributeSet attrs) {
    super(context, attrs);
            // creating new gesture detector
    gestureDetector = new GestureDetector(context, new GestureListener());
}

// skipping measure calculation and drawing

    // delegate the event to the gesture detector
@Override
public boolean onTouchEvent(MotionEvent e) {
    return gestureDetector.onTouchEvent(e);
}


private class GestureListener extends GestureDetector.SimpleOnGestureListener {

    @Override
    public boolean onDown(MotionEvent e) {
        return true;
    }
    // event when double tap occurs
    @Override
    public boolean onDoubleTap(MotionEvent e) {
        float x = e.getX();
        float y = e.getY();

        Log.d("Double Tap", "Tapped at: (" + x + "," + y + ")");

        return true;
    }
}
}