Android,布局中的透明子GLSurfaceView? [英] Android, Transparent sub-GLSurfaceView in layout?

查看:24
本文介绍了Android,布局中的透明子GLSurfaceView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
​​Android OpenGL ES 透明背景

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

I'd like to display some 3d object on top of the normal 2d ui layout screen.

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

The 2d ui screen has background image, and GLSurfaceView is child of the content layout.

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

I tried the same technique of the Translucent GLSurfaceView in ApiDemos sample,

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

but GLSurfaceView clears all and shows black background.

<?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);
...

<小时>

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


Can I preserve the underlying background image in this situation?

推荐答案

这为我解决了:

    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);

这篇关于Android,布局中的透明子GLSurfaceView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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