Search code examples
javaandroidsurfaceviewgrid-layoutandroid-gridlayout

GridLayout SurfaceView children overlays each other when changing the visibility of them


I have an activity named ScreensActivity, this activity contains a GridLayout.

Each of the GridLayout children is a custom View named ScreenView.

ScreenView consist of a SurfaceView which intended to play video from a .MP4 file.

This is the view hierarchy of the above mentioned components:

ScreensActivity
    GridLayout
        ScreenView
        ScreenView
        ScreenView
        ScreenView
        ...

Expected Behavior

What I am trying to do is to add support for changing the "state" of a ScreenView in the GridLayout to "full-screen", by disappearing (using setVisibility(GONE)) the rest of the ScreenView's, so it will fill the entire GridLayout.

Only one ScreenView at a time can be in "full-screen state"

Current Behavior

Currently, this is only working when attempting to change the "state" of the 1st ScreenView in the GridLayout (which is the expected behavior).

When attempting to change the "state" from the 2nd ScreenView and so on, I encounter the following weird behavior (see visual GIF of the examples below):

When changing a ScreenView "state" to "full-screen", it being overlaid by other ScreenView's, for example:

  • When changing the 2nd ScreenView "state" to "full-screen", the 1st ScreenView overlays him.
  • When changing the 3rd ScreenView "state" to "full-screen", both the 1st and the 2nd "screens overlay him, and so on.
  • And so on, until changing the 9th ScreenView "state" to "full-screen", all the previous ScreenView's overlay him.

Important Note

When I replace the SurfaceView (inside the ScreenView) with TextView, for example, changing the ScreenView "state" to "full-screen" executes as expected, so it seems that the problematic component which produce this weird behavior is the SurfaceView which the ScreenView consist of.

Let me know if adding the source code will help you solve my issue.

Thank you very much for your help.


Solution

  • I figured it out by replacing the SurfaceView with a TextureView which behaves exactly how I expected it to behave.