我找不到通过实际自定义视图执行此操作的方法,因此不得不返回一层。
视图的位置记录在包含每个视图的 FrameLayout 上。
在 FrameLayout 中,我最终覆盖了onTouchEvent。
我最终不得不做类似的事情:
@Override
public boolean onTouchEvent(MotionEvent event) {
float xCoord = event.getX();
float yCoord = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// Using X and Y coordinates, find out if touch event is on top of a view.
// Mark the view as touched
return true;
case MotionEvent.ACTION_UP:
// Action required once touch released.
return true;
default:
// When dragging, the default case will be called.
// Using X and Y coordinates, figure out if finger goes over a view.
// If you don't want same behaviour when going back to previous view,
// then mark it so you can ignore it if user goes back to previous view.
}
}
一旦case MotionEvent.ACTION_UP 被调用,您可以使用视图被标记的事实来了解哪些视图被触摸。如果需要,您还可以通过在标记视图时将视图放入数组中来获取顺序。