本文介绍了安卓MotionEvent.getActionIndex()和多点触控的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我试图让指针ID whene事件MotionEvent.ACTION_MOVE发生。

我做它通过调用event.getActionIndex(),但它始终是第二个返回0,第三,第四和第五的手指。

我使用姜饼2.3.3的Galaxy S I9000

这是我的code

 开关(event.getActionMasked()){
案例MotionEvent.ACTION_MOVE:{
    Log.d(D,getActionIndex()=+ event.getActionIndex());
    };打破;
}
 

这是调试结果

  05-02 19:20:08.628:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 1
05-02 19:20:08.781:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 1
05-02 19:20:08.820:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 1
05-02 19:20:08.914:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 1
05-02 19:20:09.070:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 2
05-02 19:20:09.187:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 2
05-02 19:20:09.324:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 2
05-02 19:20:09.460:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 2
05-02 19:20:09.523:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 2
05-02 19:20:09.542:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 2
05-02 19:20:09.679:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 3
05-02 19:20:09.703:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 3
05-02 19:20:09.847:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 3
05-02 19:20:10.117:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 3
05-02 19:20:10.261:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 4
05-02 19:20:10.281:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 4
05-02 19:20:10.304:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 4
05-02 19:20:10.371:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 4
05-02 19:20:10.410:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 4
05-02 19:20:10.433:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 4
05-02 19:20:10.519:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 4
05-02 19:20:10.558:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 4
05-02 19:20:10.613:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 3
05-02 19:20:10.640:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 2
05-02 19:20:10.656:DEBUG / D(4534):getActionIndex()= 0 getPointerCount()= 1
 

解决方案

我使用的3种方法委派的鼠标事件的责任。它工作正常,在我的2.3的HTC Desire S.它能够捕捉到多点触摸事件。

 公共无效processMouseMove(INT mouseX,诠释mouseY的,INT PID)
公共无效processMouseDown(INT mouseX,诠释mouseY的,INT PID)
公共无效processMouseUp(INT mouseX,诠释mouseY的,INT PID)


公共布尔onTouch(视图V,MotionEvent事件){
    INT P = event.getActionIndex();
    开关(event.getActionMasked()){
        案例MotionEvent.ACTION_DOWN:
        案例MotionEvent.ACTION_POINTER_DOWN:
            processMouseDown((int)的event.getX(对),(int)的event.getY(对),event.getPointerId(对));
        打破;
        案例MotionEvent.ACTION_POINTER_UP:
        案例MotionEvent.ACTION_UP:
            processMouseUp((int)的event.getX(对),(int)的event.getY(对),event.getPointerId(对));
            打破;
        案例MotionEvent.ACTION_MOVE:
            最终诠释historySize = event.getHistorySize();
            最终诠释pointerCount = event.getPointerCount();
            对于(INT H = 0; H< historySize; H ++){
                 为(中间体P1 = 0; P1&所述; pointerCount; P1 ++){
                    processMouseMove((int)的event.getHistoricalX(P1,h)中,(int)的event.getHistoricalY(P1,h)中,event.getPointerId(P1));
                 }
            }
            为(中间体P1 = 0; P1&其中; event.getPointerCount(); P1 ++){

                processMouseMove((int)的event.getX(P1),(int)的event.getY(P1),event.getPointerId(P1));
            }
    }
    返回true;
}
 

I am trying to get the pointer id whene the event MotionEvent.ACTION_MOVE happens.

I am doing it by calling event.getActionIndex() but it always returns 0 for the second, the third, the forth and the fifth finger.

i am using Gingerbread 2.3.3 on Galaxy S I9000

here is my code

switch (event.getActionMasked()) {
case MotionEvent.ACTION_MOVE: {
    Log.d("D","  getActionIndex()="+event.getActionIndex());
    };break;
}

This is the debug results

05-02 19:20:08.628: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=1
05-02 19:20:08.781: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=1
05-02 19:20:08.820: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=1
05-02 19:20:08.914: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=1
05-02 19:20:09.070: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=2
05-02 19:20:09.187: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=2
05-02 19:20:09.324: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=2
05-02 19:20:09.460: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=2
05-02 19:20:09.523: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=2
05-02 19:20:09.542: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=2
05-02 19:20:09.679: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=3
05-02 19:20:09.703: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=3
05-02 19:20:09.847: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=3
05-02 19:20:10.117: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=3
05-02 19:20:10.261: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=4
05-02 19:20:10.281: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=4
05-02 19:20:10.304: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=4
05-02 19:20:10.371: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=4
05-02 19:20:10.410: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=4
05-02 19:20:10.433: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=4
05-02 19:20:10.519: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=4
05-02 19:20:10.558: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=4
05-02 19:20:10.613: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=3
05-02 19:20:10.640: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=2
05-02 19:20:10.656: DEBUG/D(4534): getActionIndex()=0  getPointerCount()=1
解决方案

I am using 3 methods to delegate the responsibility of the mouse events. It works fine on my 2.3 HTC Desire S. it is able to capture multiple touch events.

public void processMouseMove(int mouseX, int mouseY, int pid)
public void processMouseDown(int mouseX, int mouseY, int pid)
public void processMouseUp(int mouseX, int mouseY, int pid)


public boolean onTouch(View v, MotionEvent event) {
    int p = event.getActionIndex();
    switch(event.getActionMasked()){
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_POINTER_DOWN:
            processMouseDown((int)event.getX(p), (int)event.getY(p), event.getPointerId(p));
        break;
        case MotionEvent.ACTION_POINTER_UP:
        case MotionEvent.ACTION_UP:
            processMouseUp((int)event.getX(p), (int)event.getY(p), event.getPointerId(p));
            break;
        case MotionEvent.ACTION_MOVE:
            final int historySize = event.getHistorySize();
            final int pointerCount = event.getPointerCount();
            for (int h = 0; h < historySize; h++) {
                 for (int p1 = 0; p1 < pointerCount; p1++) {
                    processMouseMove((int)event.getHistoricalX(p1, h), (int)event.getHistoricalY(p1, h), event.getPointerId(p1));
                 }
            }
            for (int p1 = 0; p1 < event.getPointerCount(); p1++) {

                processMouseMove((int)event.getX(p1), (int)event.getY(p1), event.getPointerId(p1));
            }
    }
    return true;
}

这篇关于安卓MotionEvent.getActionIndex()和多点触控的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 17:46