简体   繁体   中英

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 View s 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM