# Put layout over Surfaceview

I have this problem: I'm trying to create new RelativeLayout over whole screen - which also contains SurfaceView in the middle - and display some things on this RelativeLayout (in my case Imageview containing animation). Almost everything is working ok - Imageview is displayed, animation is working... but SurfaceViews drawings (Bitmaps) are on the top of my RelativeLayout with Imageview, which I'm trying to appear it on top.

Calling bringtofront() doesn't work. Although I've created RelativeLayout with ImageView after SurfaceView, it's still below it.

So my question is: how to bring this RelativeLayout with ImageView to the top of SurfaceView?

In Activity:

// Layout, on which I'm adding Surfaceview programmatically
RelativeLayout layout = (RelativeLayout) findViewById(R.id.middle_layout);

// Layout which should be top over everything
RelativeLayout topLayout = new RelativeLayout(getApplicationContext());
RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
topLayout.setLayoutParams(rlp);

// Although I'm adding SurfaceView first and Relative second, no hierarchy order is visible...
// OR
// ^ Both attempts are displayed under SurfaceView


SurfaceView class:

public class SurfaceView extends SurfaceView implements SurfaceHolder.Callback
{
public SurfaceView (Context context)
{
super(context);

this.setZOrderOnTop(true);

getHolder().setFormat(PixelFormat.TRANSPARENT);

setFocusable(true);
}

...
}


PS: I need to create SurfaceView programmatically.

Thanks for any help!

• Hi @johnyX, did you found a solution? Oct 5 '19 at 0:40

Result: it's not possible. surfaceView.setZOrderOnTop(true) will cause SF to be on the very top, so you just can't draw anything over it. And with setZOrderOnTop(false), you can put views over SF, but its background won't be transparent (and that's what I need too..). And that's quite sad.