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.addView(new SurfaceView((getApplicationContext())));

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

// 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)






PS: I need to create SurfaceView programmatically.

Thanks for any help!

  • \$\begingroup\$ Hi @johnyX, did you found a solution? \$\endgroup\$
    – Derzu
    Commented Oct 5, 2019 at 0:40

2 Answers 2


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.


It is possible to draw over the surface view with another fragment when it is added programmatically over the top of the activity/fragment that contains the surface view.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .