简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM