我试图获取MotionEvent.ACTION_MOVE事件发生时的指针ID.
我通过调用event.getActionIndex()来做它,但它总是为第二个,第三个,第四个和第五个手指返回0.
我在galaxy S I9000上使用Gingerbread 2.3.3
这是我的代码
switch (event.getActionMasked()) {case MotionEvent.ACTION_MOVE: { Log.d("D"," getActionIndex()="+event.getActionIndex()); };break;}
这是调试结果
05-02 19:20:08.628: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=105-02 19:20:08.781: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=105-02 19:20:08.820: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=105-02 19:20:08.914: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=105-02 19:20:09.070: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=205-02 19:20:09.187: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=205-02 19:20:09.324: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=205-02 19:20:09.460: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=205-02 19:20:09.523: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=205-02 19:20:09.542: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=205-02 19:20:09.679: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=305-02 19:20:09.703: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=305-02 19:20:09.847: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=305-02 19:20:10.117: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=305-02 19:20:10.261: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=405-02 19:20:10.281: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=405-02 19:20:10.304: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=405-02 19:20:10.371: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=405-02 19:20:10.410: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=405-02 19:20:10.433: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=405-02 19:20:10.519: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=405-02 19:20:10.558: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=405-02 19:20:10.613: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=305-02 19:20:10.640: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=205-02 19:20:10.656: DEBUG/D(4534): getActionIndex()=0 getPointerCount()=1
解决方法:
我正在使用此代码来转储事件,并且它运行良好.
/** Show an event in the LogCat vIEw, for deBUGging */private voID dumpEvent(MotionEvent event) { String names[] = { "DOWN" , "UP" , "MOVE" , "CANCEL" , "OUTSIDE" , "POINTER_DOWN" , "POINTER_UP" , "7?" , "8?" , "9?" }; StringBuilder sb = new StringBuilder(); int action = event.getAction(); int actionCode = action & MotionEvent.ACTION_MASK; sb.append("event ACTION_" ).append(names[actionCode]); if (actionCode == MotionEvent.ACTION_POINTER_DOWN || actionCode == MotionEvent.ACTION_POINTER_UP) { sb.append("(pID " ).append( action >> MotionEvent.ACTION_POINTER_ID_SHIFT); sb.append(")" ); } sb.append("[" ); for (int i = 0; i < event.getPointerCount(); i++) { sb.append("#" ).append(i); sb.append("(pID " ).append(event.getPointerID(i)); sb.append(")=" ).append((int) event.getX(i)); sb.append("," ).append((int) event.getY(i)); if (i + 1 < event.getPointerCount()) sb.append(";" ); } sb.append("]" ); Log.d(TAG, sb.toString());}
我把它从this ZDNET article下来了,所以我不能相信它.我在AndroID 3.0上运行,但示例代码最初是为早期版本的AndroID编写的,所以它也适用于你.
看起来你需要调用getPointerID而不是getActionIndex.
总结以上是内存溢出为你收集整理的Android MotionEvent.getActionIndex()和MultiTouch全部内容,希望文章能够帮你解决Android MotionEvent.getActionIndex()和MultiTouch所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)