2015-06-24 17 views
-3

以下是我的場景:LinearLayout作爲Activity的主要佈局。版式包含一個ImageView,它有自己的onClickListener輕鬆保持聽衆在觸摸屏幕的同時工作

當用戶將手指放在屏幕上時觸發ImageView監聽器的最簡單方法是什麼?這是用戶握住設備並錯誤地觸摸屏幕(因此onTouch觸發)但想要按下ImageView的一般場景。在這種情況下,由於屏幕已經被觸摸,當他按下他時,沒有任何反應。

enter image description here

回答

0

我想你可以實現通過使用ACTION_DOWN & ACTION_POINTER_DOWN,其中後是第二觸摸相同。你需要在你的touchlistner中處理這些事件。這個監聽器可以在你的根佈局上。

public boolean onTouchEvent(MotionEvent event) { 
} 

See here, some excerpts are

When multiple pointers touch the screen at the same time, the system generates the following touch events: 
ACTION_DOWN—For the first pointer that touches the screen. This starts the gesture. The pointer data for this pointer is always at index 0 in the MotionEvent. 
ACTION_POINTER_DOWN—For extra pointers that enter the screen beyond the first. The pointer data for this pointer is at the index returned by getActionIndex(). 
ACTION_MOVE—A change has happened during a press gesture. 
ACTION_POINTER_UP—Sent when a non-primary pointer goes up. 
ACTION_UP—Sent when the last pointer leaves the screen. 
+0

謝謝。我希望有一個更簡單的方法,但這將不得不做。 – Alin