Reputation: 755
I have a SurfaceView with a transparent background, on which i draw stuff, and on top of that i want an ImageView to be drawn.
In order for the SurfaceView to be transparent i have to set surfaceView.setZOrderOnTop(true)
, but the problem is that now, my surfaceview's canvas is drawn on top of the imageview,
which makes sense because of setZOrderOnTop(true)
.
My question is, is there a way to achieve what i want? a SurfaceView with transparent background and an ImageView on top of it?
Thanks, Vlad
Edit: Ok so this isn't possible. See fadden's answer below, or https://www.youtube.com/watch?v=duefsFTJXzc&feature=feedwll&list=WL for deeper understanding.
Upvotes: 2
Views: 1928
Reputation: 7146
You can do that placing the ImageView inside a PopupWindow. It can come from an xml layout.
Example:
View popupView = layoutInflater.inflate(R.layout.popuplayout, null);
PopupWindow myPopup = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
myPopup.setOutsideTouchable(true);
myPopup.showAtLocation(rootView, Gravity.TOP | Gravity.LEFT, 100, 100);
Where 100, 100 is your x, y position.
Upvotes: 0
Reputation: 52313
You can't do what you want with a single SurfaceView
.
All Views are composed onto a single layer. The SurfaceView
has two parts, the "View" part (which is just a transparent place-holder) and the "Surface" part. The latter is a completely separate layer.
So you can put the "Surface" part above all other Views or below all other Views, but you can't put it in between. A TextureView
will do what you want, but you need to be using API 14+ for that.
You can, however, have more than one SurfaceView
, and put the "Surface" layers at different Z-levels. There are good reasons not to do this -- once you have more than N surfaces the system compositor may switch to a less-efficient operating mode -- but it's possible. See the "Multi-surface test" in Grafika for an example.
Upvotes: 2