thefrugaldev
thefrugaldev

Reputation: 1629

Button on top of SurfaceView with setZOrderOnTop set to true in Android

I have two surfaceviews in an app and one surfaceview needs to overlap the other surfaceview. For example, say there are two surfaceviews SurfaceView A and SurfaceView B. B needs to be on top of A which is accomplished by setting setZOrderOnTop(true) on B.

Now, I want to display some text or buttons on top of B but because it has Z order set as true the text or buttons added doesn't show on top but come underneath it. If the setZOrderOnTop property is not set then the text views and buttons does show up on top but then B doesn't overlap A.

I have tried placing SurfaceView B and the textview or buttons in FrameLayout but still it appears under B. Is there a way that z order can be set to true and still text or buttons can come on top of it?

Upvotes: 5

Views: 4653

Answers (1)

thefrugaldev
thefrugaldev

Reputation: 1629

I was able to resolve the issue by using setZOrderMediaOverlay(true) instead of setZOrderOnTop.

The method setZOrderOnTop if set to true will always be on top of the window. So, in order to have overlay view over surface view setZOrderMediaOverlay should be used.

For more information, refer setZOrderMediaOverlay document here.

Upvotes: 9

Related Questions