我試圖讓事件MotionEvent.ACTION_MOVE發生時的指針ID。Android MotionEvent.getActionIndex()和MultiTouch
我正在通過調用event.getActionIndex()來做到這一點,但它總是返回0爲第二,第三,第四和第五手指。
我使用薑餅2.3.3的Galaxy S I9000
這裏是我的代碼
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()=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
該代碼是從[這裏](http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2-part-3-understanding- touch-events/1775?tag = mantle_skin; content) – 2011-05-02 19:03:01
謝謝Jim,我用你提供給我的代碼,它工作得很好,除非它不提供指針ID導致ACTION_MOVE事件,這就是我得到的(05 -02 20:15:38.863:DEBUG/MTView(5033):event ACTION_MOVE [#0(pid 0)= 61,52;#1(pid 1)= 265,360])和(05-02 20:15:38.878 :DEBUG/MTView(5033):event ACTION_MOVE [#0(pid 0)= 61,52;#1(pid 1)= 256,368]),因爲我移動了第二根手指,這兩個事件是連續的。謝謝你,吉姆。 – kamelbox 2011-05-02 19:37:05
不客氣,是的,它並沒有告訴你哪個手指引起了事件。它只是告訴你每個手指的當前位置。當然,如果您將當前位置與以前的位置進行比較,則可以推斷出哪根手指導致了這種情況。 – 2011-05-02 20:02:38