Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add view on top of transparent SurfaceView?

This answer describes how to make a SurfaceView with a transparent background.

However it requires setZOrderOnTop(true) to be called on the SurfaceView, which unsurprisingly puts the SurfaceView on top of the other views.

This isn't exactly what I want. Given Views A, C, and SurfaceView B I would like to order the views as A behind B behind C.

If B weren't a SurfaceView with a transparent background this would simply be:

<RelativeLayout>
  <ViewA>
  <ViewB>
  <ViewC>
</RelativeLayout>

Is it possible to achieve this when B is a SurfaceView with a transparent background?

like image 896
GDanger Avatar asked Sep 22 '14 22:09

GDanger


1 Answers

There are four possible layers with the current SurfaceView API. From top to bottom:

  • setZOrderOnTop
  • (Views)
  • setZOrderMediaOverlay
  • default

The SurfaceView surface, and the surface with all of the Views, are composited by the system compositor. You cannot Z-order sandwich a SurfaceView surface between two Views. (If you want the full details, read this article. See also the multi-surface test activity in Grafika, which software-renders to three overlapping transparent SurfaceViews.)

What you may want to do is use a TextureView (API 14+), which has many of the same properties but interacts fully with Views. If you were using Canvas to draw on your SurfaceView, you may be able to use a custom View, which has the added advantage of hardware accelerated rendering.

like image 57
fadden Avatar answered Sep 30 '22 14:09

fadden