分层SurfaceViews中的FrameLayout Android中 [英] Layered SurfaceViews in a FrameLayout in Android

查看:871
本文介绍了分层SurfaceViews中的FrameLayout Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个增强现实应用程序的Andr​​oid和已经遇到分层表面看法的问题。我需要一个面视图显示相机preVIEW上,我将覆盖的图形,我需要从表面上看,把我的显卡上。这第二个面也需要上面的摄像头preVIEW要绘制,但有一个透明背景。在我目前的执行情况,我都面视图工作,并出现作为他们应该,但背景是不透明的,因此不存在外观绘制叠加在相机preVIEW表面图形第二面视图视图。如何才能实现这一目标?当搜索无数堆栈溢出的问题,以及其他论坛我遇到有关此事的许多相互矛盾的观点。有人说,分层表面意见Android是不可能的,而其他人说,这是一个使用不同布局的问题具体,我实现包括两个视图(的FrameLayout与LinearLayout中?):一类,CustomCameraView,延伸SurfaceView,和类,CustomDrawView,这还延伸SurfaceView包含在与CustomDrawView出现在CustomCameraView后的FrameLayout。怎么可以把这些分层,这样CustomDrawView似乎叠加在CustomCameraView?

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 preview onto which I will overlay graphics, and I need a surface view to draw my graphics on. This second surface also needs to be drawn above the camera preview but have a transparent background. In my current implementation, I have both surface views working and appearing as they are supposed to, but the background is not transparent and therefore there is no appearance of the second surface view with the graphics drawn being superimposed on the camera preview surface view. How could this be achieved? Upon searching numerous stack overflow questions as well as other forums I've come across many conflicting opinions pertaining to this matter. Some say that layering surface views in Android is impossible whilst others say that it is a matter of using a different layout (FrameLayout vs. LinearLayout?) Specifically, my implementation includes two views: a class, CustomCameraView, that extends SurfaceView, and a class, CustomDrawView, that also extends SurfaceView contained in a FrameLayout with the CustomDrawView appearing after the CustomCameraView. How can these be layered so that CustomDrawView seems superimposed on CustomCameraView?

推荐答案

我想很多人都尝试过这一点。一位谷歌Enginee说(这里)显然,你应该避免堆叠面视图。即使有人已经发现了一些窍门来做到这一点,它可能是不兼容的,并会导致问题。

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:

  • 查看顶面视图(S)

使用从表面上看您的相机preVIEW和堆栈在它上面的意见。这种方法的缺点是,在正常的意见)绘制较慢和b)发生在UI线程。你可以围绕b获得),如果你实现了自己的线程。但是总体来说,这可能是要走的路,如果你的覆盖包含类似的UI元素或几个可绘制那些不需要经常更新。

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.

  • 请一切都在一个SurfaceView

这将使运行时的哟更好的性能和更小的开销。你只有一个SurfaceView。复合材料在你的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.

  • 请一切都在一个GLSurfaceView

这是可能的方式去进行真正的性能。像以上,但随着摄像机视图的渲染到OpenGL的纹理在 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.

这篇关于分层SurfaceViews中的FrameLayout Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆