문제

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