简体   繁体   English

如何将重叠的 SurfaceView 放在前面?

[英]How to bring overlapping SurfaceView to the front?

I am doing a Matlab-style heat map plot in Android and decided to use an overlapping combination of a GLSurfaceView to do the heat map (if you don't know what a heat map is, don't worry about it) and a SurfaceView to do the axes labelling, bitmaps on top of the heat map, etc. That way the GLSurfaceView can just do the things that it is good at and the canvas-based SurfaceView can just do the things that it is good at. I am doing a Matlab-style heat map plot in Android and decided to use an overlapping combination of a GLSurfaceView to do the heat map (if you don't know what a heat map is, don't worry about it) and a SurfaceView做轴标签,热map等上面的位图。这样GLSurfaceView可以做它擅长的事情,而基于画布的SurfaceView可以做它擅长的事情。 The SurfaceView has a transparent background so that the GLSurfaceView can be seen through it. SurfaceView 具有透明背景,因此可以通过它看到 GLSurfaceView。

My problem is that the GLSurfaceView appears to come to the "top" when it is rendered, and I am not able to force the SurfaceView to go to the top using the "bringToFront()" method.我的问题是 GLSurfaceView 在渲染时似乎到达了“顶部”,我无法使用“bringToFront()”方法将 SurfaceView 强制到 go 到顶部。 Is there a way to do this?有没有办法做到这一点? I have turned continuous rendering off, so I manually render the SurfaceView ("auxiliary") when I render the GLSurfaceView.我已经关闭了连续渲染,所以我在渲染 GLSurfaceView 时手动渲染了 SurfaceView(“辅助”)。

public void onDrawFrame(GL10 gl) {
    Log.d(TAG, "HeatMapView onDrawFrame");

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

    heatMap.draw(gl);
    auxiliary.draw(); // This is the SurfaceView draw
}  


/**
 * This function draws our heat map on screen.
 * @param gl
 */
public synchronized void draw(GL10 gl) {
    Log.d(TAG, "HeatMap draw");
    if (!openGlSetUp) {
        gl.glFrontFace(GL10.GL_CW);
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
        gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuffer);
        openGlSetUp = true;
    }

    gl.glDrawElements(GL10.GL_TRIANGLES, curIndexBufferLen, GL10.GL_UNSIGNED_SHORT, indexBuffer);
    dataDirty = false;
}

/**
 * This function draws the axes and bitmaps.
 */
public void draw() {
    Log.d(TAG, "draw");
    Canvas canvas = holder.lockCanvas(null);

    canvas.drawColor( 0, PorterDuff.Mode.CLEAR ); 
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
    paint.setTextSize(16);
    paint.setColor(Color.argb(255,255,255,255));
    canvas.rotate(90f, 300, 300);
    canvas.drawText("Azimuth", 250, 590, paint);
    canvas.rotate(-90f, 300, 300);
    canvas.drawText("Freq (GHz)", 525, 555, paint);

    holder.unlockCanvasAndPost(canvas);
    bringToFront();
}

protected void onVisibilityChanged (View changedView, int visibility) {
    bringToFront();
}

Obviously this isn't all the code- I tried to show the most relevant parts.显然这不是所有的代码——我试图展示最相关的部分。 Any ideas on how I can get the SurfaceView (auxiliary) on top?关于如何将 SurfaceView(辅助)置于顶部的任何想法?

The answer given in this thread .这个线程中给出了答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM