Search code examples
androidandroid-layoutoverlaygesturegesture-recognition

How make an Overlay who only detect gesture. Android 4.x


I try to make a service who put an invisible overlay (transparent layout) on top of everything and detect the gesture for bind an event.
but when the overlay is on top, everything under is inaccessible (Applications).
I have use this example : http://www.jawsware.mobi/code_OverlayView/

How to create an overlay to catch gesture without trouble the others applications.


Solution

  • Let's assume you ordinarily would call setContentView(R.layout.main), but on first run, you want to have this overlay.

    Step #1: Create a FrameLayout in Java code and pass that to setContentView().

    Step #2: Use LayoutInflater to inflate R.layout.main into the FrameLayout.

    Step #3: Use LayoutInflater to inflate the overlay into the FrameLayout.

    Step #4: When the user taps the button (or whatever) to dismiss the overlay, call removeView() to remove the overlay from the FrameLayout.

    Since the overlay is a later child of the FrameLayout, it will float over top of the contents of `R.layout.main