0
\$\begingroup\$

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(
                                 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...
layout.addView(topLayout);
// OR
root_layout.addView(topLayout);
// ^ Both attempts are displayed under SurfaceView

SurfaceView class:

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

            getHolder().addCallback(this);

            this.setZOrderOnTop(true);

            getHolder().setFormat(PixelFormat.TRANSPARENT);

            setFocusable(true);
    }

    ... 
}

PS: I need to create SurfaceView programmatically.

Thanks for any help!

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

2 Answers 2

2
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

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