让听众在触摸屏幕时保持工作的简单方法

Easy way to keep the listeners working while touching the screen

这里是我的场景:一个LinearLayout作为主布局的Activity。布局包含一个 ImageView,它有自己的 onClickListener.

当用户将手指放在屏幕上时,触发 ImageView 侦听器的最简单方法是什么。这是一种一般情况,用户握住设备并错误地触摸了屏幕(因此触发了 onTouch)但想要按下 ImageView。在这种情况下,由于屏幕已经被触摸,当按下 he ImageView 时,没有任何反应。

我想你可以通过使用 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.