【问题标题】:Android, Transparent sub-GLSurfaceView in layout? [duplicate]Android,布局中的透明子GLSurfaceView? [复制]
【发布时间】:2010-03-23 08:43:22
【问题描述】:

可能重复:
Android OpenGL ES Transparent Background

我想在普通的 2d ui 布局屏幕上显示一些 3d 对象。

2d ui 屏幕有背景图片,GLSurfaceView 是内容布局的子级。

我在 ApiDemos 示例中尝试了与半透明 GLSurfaceView 相同的技术,

但 GLSurfaceView 会清除所有内容并显示黑色背景。


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"    
    android:background="@drawable/my_background_image"
>

...

<android.opengl.GLSurfaceView android:id="@+id/glview"  
    android:layout_width="fill_parent"
    android:layout_height="300px"
    android:windowIsTranslucent="true" (i'm not sure this is right)
/>
</LinearLayout>

setContentView(R.layout.main);
...
glview = (GLSurfaceView) findViewById(R.id.glview);
glview.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
glview.getHolder().setFormat(PixelFormat.TRANSLUCENT);
glview.setRenderer(this);
...
gl.glClearColor(0, 0, 0, 0);
...

在这种情况下我可以保留底层背景图片吗?

【问题讨论】:

    标签: android opengl-es background transparent


    【解决方案1】:

    这为我解决了:

        glview = (GLSurfaceView)findViewById(R.id.glview); 
    
        glview.setEGLConfigChooser(8,8,8,8,16,0);
    
        glview.setRenderer(new MyRenderer(this));
        glview.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    
        // this made it work for me - works only from sdk level 6 on, though....
        glview.setZOrderOnTop(true);
    

    【讨论】:

    • @P.Melch 这使 GlSurfaceView 位于所有视图之上。现在我无法在 GlSurfaceView 上设置另一个视图。有没有其他方法可以使 GlSurfaceView 透明。
    • @P.Melch 同样的问题 Zorder-top 使其他视图落后于 GLsurfaceview
    • AFAIK 使用表面视图的唯一方法是选择正面或背面放置。如果您想要更复杂的布局,我认为 TextureView 适合您(不过从 API 14 开始可用)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-02
    • 2013-05-21
    • 2013-07-23
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多