Daiwik Daarun
Daiwik Daarun

Reputation: 3974

Android: Passing Touch Events from View

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;
}

Upvotes: 2

Views: 3781

Answers (1)

Daiwik Daarun
Daiwik Daarun

Reputation: 3974

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);
}

Upvotes: 6

Related Questions