Once your View returns true to say that it's consuming the touch event, the rest of the views won't receive it. What you can do is make a custom ViewGroup
(you say you have a grid, I'll just assume GridView
?) that intercepts and handles all touch events:
public class InterceptingGridView extends GridView {
private Rect mHitRect = new Rect();
public InterceptingGridView (Context context) {
super(context);
}
public InterceptingGridView (Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent (MotionEvent ev) {
//Always let the ViewGroup handle the event
return true;
}
@Override
public boolean onTouchEvent (MotionEvent ev) {
int x = Math.round(ev.getX());
int y = Math.round(ev.getY());
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.getHitRect(mHitRect);
if (mHitRect.contains(x, y)) {
/*
* Dispatch the event to the containing child. Note that using this
* method, children are not guaranteed to receive ACTION_UP, ACTION_CANCEL,
* or ACTION_DOWN events and should handle the case where only an ACTION_MOVE is received.
*/
child.dispatchTouchEvent(ev);
}
}
//Make sure to still call through to the superclass, so that
//the ViewGroup still functions normally (e.g. scrolling)
return super.onTouchEvent(ev);
}
}
How you choose to handle the event depends on the logic that you require, but the takeaway is to let the container view consume all of the touch events, and let it handle dispatching the events to the children.