首页 > 代码库 > Android多触点总结

Android多触点总结

 

文章部分内容参考:

http://blog.csdn.net/barryhappy/article/details/7392326

 

总结:

1. event.getX()可以得到x的坐标,里面的参数0表示最开始的触摸;参数为1时表示第二个触摸点;

2. MotionEvent.ACTION_DOWN:在第一个点被按下时触发

3. MotionEvent.ACTION_UP:当屏幕上唯一的点被放开时触发

4. 如果食指先触摸屏幕,会触发ACTION_DOWN;然后抬起,会触发ACTION_UP;如果食指先触摸屏幕,中指再触摸屏幕,则中指会触发ACTION_POINTER_2_DOWN;此后抬起的手指就会触发ACTION_POINTER_2_UP(在本例中,不管是食指还是中指抬起);接着,可能再会按下和抬起,触发的则是ACTION_POINTER_1_DOWNACTION_POINTER_1_DOWN

 

 

@SuppressWarnings("deprecation")    public boolean onTouchEvent(MotionEvent event) {        int action = event.getAction();                    if (event.getPointerCount() == 2)        {          x1 = event.getX(1);          y1 = event.getY(1);        }        x0 = event.getX(0);        y0 = event.getY(0);                switch (action) {        case MotionEvent.ACTION_DOWN:            HandleDown(getArea(x0, y0));            break;        case MotionEvent.ACTION_UP:            HandleUp(getArea(x0, y0));            break;                    //按下两个地方时,先抬起第1个,然后再按下,才会触发 ACTION_POINTER_1_DOWN        case MotionEvent.ACTION_POINTER_1_DOWN:            HandleDown(getArea(x0, y0));            break;                       case MotionEvent.ACTION_POINTER_1_UP:            HandleUp(getArea(x0, y0));            break;                    case MotionEvent.ACTION_POINTER_2_DOWN:            HandleDown(getArea(x1, y1));            break;                    case MotionEvent.ACTION_POINTER_2_UP:            HandleUp(getArea(x1, y1));            break;                       }                return super.onTouchEvent(event);    }