通过GLSurfaseView渲染视图组件

时间:2014-10-17 10:26:29

标签: java android glsurfaceview

我想在GL表面上放置一些视图,最后我提出了结构解决方案:

enter image description here

我有这样的布局结构,根布局 - FrameLayout:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="fill_parent>

    <GLSurfaceView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginLeft="100dp"
        android:layout_marginRight="100dp"/>

    <RelativeLayout 
        android:layout_width="match_parent"
        android:layout_height="fill_parent">

    // here I put all my views which I want to be on top of GL surface

    </RelativeLayout>

</FrameLayout>

它适用于我的三星galaxy s3和仿真器(来自android SDK和Genymotion)。 但它在Xperia上失败了,由于某种原因,在这个设备上GLSurfaceView上的所有图形对象都没有显示。

请您给我一些建议 - 我的方法是否正确以及在某些设备上可能导致问题的原因?

还有其他更正确的方法在GLSurfaceView上显示来自android sdk的视图吗?

1 个答案:

答案 0 :(得分:1)

背景:GLSurfaceView曲面是一个完全独立的层,由系统而不是应用程序合成。它将出现在所有视图的上方或下方,并且不能夹在它们之间。相对于View层有三种可能的Z排序,下面两个,上面一个。 Grafika&#34;多表面测试&#34;演示多个重叠的透明SurfaceView曲面,与视图共享屏幕。

默认情况下,曲面显示在视图后面,这似乎是您想要的。如果您没有看到GLSurfaceView曲面,可能是因为它顶部的视图背景不透明。我的猜测是,默认的UI主题在不同的设备之间是不同的,一个是提供透明度而另一个不是。

在API 14+上,框架提供了一种使用TextureView混合视图和曲面的方法。将GLES与TextureView一起使用并不比GLSurfaceView困难得多 - 您只需要进行自己的EGL设置。 Grafika的GLES库演示了如何做到这一点。