View が true を返し、タッチ イベントを消費していることを示すと、残りのビューはそれを受け取りません。あなたができることは、すべてのタッチイベントをインターセプトして処理するカスタムを作成することViewGroup
です (グリッドがあると言いますが、私は仮定しますか?)。GridView
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);
}
}
イベントをどのように処理するかは、必要なロジックによって異なりますが、重要なのは、コンテナー ビューがすべてのタッチ イベントを消費し、子へのイベントのディスパッチを処理できるようにすることです。