In my app, I have a RelativeLayout that contains two other RelativeLayouts. The first RelativeLayout is used for an OpenGL view. The second is used to place Buttons and other Views. I am able to process touch events fine in OpenGL, unless they take place on one of the Views.

This is normally fine, but at times I want the OpenGL view to receive the event as well, but the View in front of it is always consuming the touch event. I have tried using the following, with no luck:

@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
    onTouchEvent(ev);
    return false;
}
有帮助吗?

解决方案

Rather than overwrite onInterceptTouchEvent, I needed dispatchTouchEvent which is a method of Activity. In dispatchTouchEvent I distributed the MotionEvent as needed. Here is an example:

public boolean dispatchTouchEvent(MotionEvent ev){
    mGLView.onTouchEvent(ev); //The openGL view
    return super.dispatchTouchEvent(ev);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top