Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在多个视图上触发悬停事件_Android - Fatal编程技术网

Android 在多个视图上触发悬停事件

Android 在多个视图上触发悬停事件,android,Android,在我的布局中,我有50个儿童视图。 当我在每个视图上拖动(悬停)而不释放手指时,我希望所有触摸的视图都能改变它们的颜色 我不知道我应该用什么来做这件事。 我尝试使用onHover(),但它不起作用您可以像这样使用android.view.MotionEvent.ACTION\u DOWN和android.view.MotionEvent.ACTION\u MOVE yourview.setOnTouchListener(new OnTouchListener () { public boole

在我的布局中,我有50个儿童视图。
当我在每个视图上拖动(悬停)而不释放手指时,我希望所有触摸的视图都能改变它们的颜色

我不知道我应该用什么来做这件事。

我尝试使用onHover(),但它不起作用

您可以像这样使用
android.view.MotionEvent.ACTION\u DOWN
android.view.MotionEvent.ACTION\u MOVE

yourview.setOnTouchListener(new OnTouchListener () {
 public boolean onTouch(View view, MotionEvent event) {

if (event.getAction() == android.view.MotionEvent.ACTION_DOWN) {
  Log.d("TouchTest", "Finger touched");
} 
else if (event.getAction() == android.view.MotionEvent.ACTION_MOVE) {
  Log.d("TouchTest", "Finger being dragged");
}
else if (event.getAction() == android.view.MotionEvent.ACTION_UP) {
  Log.d("TouchTest", "finger lifted from screen");
}
}
}

感谢您的回答,但当我在每个子视图上实现setOnTouchListener时,即使我在另一个子视图上,onTouch也只返回我第一次接触的视图。Thanks@Jovan在这种情况下,您需要实现一个定制的
recyclerview
,如下所示