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!