本文介绍了没有setZOrderonTop的Android GLSurfaceView透明背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起我的英语.

我的工作基于https://github.com/harism/android_page_curl/

经过数小时的研究,我找到了一些解决方案,但并不是针对我在应用程序中遇到的所有问题.我在使用 GLSurfaceView 时遇到了一些问题.我有一个带有 relativeLayout、一个 GLSurfaceView 和一个叠加层的背景.

After many hours of research, I have found a few solutions, but not for all the issues what I have in my application.I've some trouble with a GLSurfaceView.I've got a background with a relativeLayout, a GLSurfaceView, and an overlay on top.

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/background"
    android:layout_width="match_parent"
    android:background="@layout/backgroundrepeat"
    android:layout_height="match_parent">
<com.m2y.foxprez.view.CurlView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/openglview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/overlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
</RelativeLayout>

当我初始化我的视图时:

When I init my view :

setEGLConfigChooser(8,8,8,8,16,0);
setRenderer(renderer);
getHolder().setFormat(PixelFormat.TRANSLUCENT);
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
setZOrderMediaOverlay(true);

在我的渲染器中:

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    gl.glClearColor(0f, 0f, 0f, 0f);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
    gl.glHint(GL10.GL_LINE_SMOOTH_HINT, GL10.GL_NICEST);
    gl.glHint(GL10.GL_POLYGON_SMOOTH_HINT, GL10.GL_NICEST);
    gl.glEnable(GL10.GL_LINE_SMOOTH);
    gl.glDisable(GL10.GL_DEPTH_TEST);
    gl.glDisable(GL10.GL_CULL_FACE);
}

public synchronized void onDrawFrame(GL10 gl) {
    gl.glClearColor(0f,0f,0f,0f);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    gl.glLoadIdentity();
}

经过多次研究,我目前对这个结果感到困惑:
使用 setZOrderOnTop,我有背景,但覆盖在视图下方.
使用 setZOrderMediaOverlay,我得到了覆盖,但背景是黑色的.

After multiple research, I am currently blocked with this result:
with setZOrderOnTop, i've got background, but the overlay is under the view.
with setZOrderMediaOverlay, i've got the overlay, but the background is black.

有人可以帮助我吗?

推荐答案

这对我有用:

final GLSurfaceView glView = (GLSurfaceView) findViewById(R.id.glView);

glView.setZOrderOnTop(true);
glView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
glView.getHolder().setFormat(PixelFormat.RGBA_8888);
glView.setRenderer(new MyRenderer());
glView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

在这里找到:http://andrewhague.wordpress.com/2011/05/24/how-to-set-a-transparent-glsurfaceview/

这篇关于没有setZOrderonTop的Android GLSurfaceView透明背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 08:56