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

本秂侑毒 提交于 2019-12-11 01:45:22

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/39472277/button-on-top-of-surfaceview-with-setzorderontop-set-to-true-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!