shuky chen
shuky chen

Reputation: 21

SurfaceView becomes tranansparent onCreate and onDestroy

I am using a SurfaceView to show a camera preview in my activity. The SurfaceView is placed inside a fragment.

When this fragment is shown the Surfaceview is punching a hole in my activity, letting the user to see whatever is behind my activity.

After the camera is fully loaded, everything is fine. But when I want to switch back to another fragment the same thing happens.

How can I prevent this behavior?

Thanks, Shuky

Upvotes: 0

Views: 231

Answers (1)

fadden
fadden

Reputation: 52353

SurfaceViews have two parts, the "surface" part and the "view" part.

The "view" part is a transparent hole that gets laid out with all the other views. All of the views are composited onto a single layer. The "surface" part is a completely separate layer that is rendered behind the view layer. It has the same position and size as the "view" part, but appears behind all views.

If you need the "view" interaction to be a bit less weird, and you're using API 14 or later, you can use TextureView for your Camera preview instead.

Upvotes: 0

Related Questions