Frage

My Android application is essentially a Surface View implementing the "SurfaceHolder.Callback" interface. I'm displaying a graph of 2-D data in in more-or-less real time. Also, I've added a Text View to display some additional data superimposed over the Surface View.

My current problem is that the Surface View handles a variety of gestures and touches, but the Text View seems to be intercepting the touches.

How can I pass events from the Text View to the underlying (literally, in the Relative Layout) Surface View for handling??

Thanks,
R.

War es hilfreich?

Lösung

I was hoping not to have to do this (answer my own question) but here's what I think I know from a few posts on SO:

In an Android Relative Layout, the view "on top" gets the event first. In my case, the Text View on top of the Surface View isn't supposed to do anything with anything, so it was necessary to pass all events "down" the stack. I accomplished that with this:

textView.setOnTouchListener (new View.OnTouchListener()
{
    @Override
    public boolean onTouch (View v, MotionEvent event)
    {
        return false;
    }
});

The annoying part about this (in my opinion) is the deceiving nature of the Android help text on the matter which says:

"Returns - True if the listener has consumed the event, false otherwise."

The tone of this seems to me (again, my opinion) to have Cause and Effect reversed. I suppose it's nitpicking, but the text should probably say something along the lines of, "Return TRUE to indicate the event SHOULD BE CONSUMED (by the OS, it would seem), false otherwise."

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top