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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With