Layered SurfaceViews in a FrameLayout in Android

后端 未结 2 733
别跟我提以往
别跟我提以往 2020-12-15 13:40

I am attempting to build an augmented reality application for Android and have come across the problem of layering surface views. I need a surface view to display the camera

2条回答
  •  失恋的感觉
    2020-12-15 13:52

    I think a lot of people have tried this. A Google Enginee stated (here) clearly, that you should avoid stacking Surface Views. Even if somebody has found some trick to do it, it is probably incompatible and will lead to problems.

    I think this gives three options, depending on your requirements:

    • View(s) on Top of Surface View

    Use a Surface View for the Camera preview and stack Views on top of it. The disadvantage of this approach is that drawing on "normal" Views a) is slower and b) takes place in the UI thread. You can get around b) if you implement the threads yourself. But generally, that is probably the way to go if your overlays contain something like UI elements or a few Drawables that don't need to be updated too often.

    • Do everything in a SurfaceView

    This will give yo better performance and less overhead during runtime. You have just one SurfaceView. Composite the overlays on your SurfaceView and and draw everything there. Of course, you can combine both approaches.

    • Do everything in a GLSurfaceView

    This is probably the way to go for real performance. Like above, but with the camera view rendering to a OpenGL texture in a GLSurfaceView.

提交回复
热议问题