我正在Android中进行Matlab风格的热图绘图,并决定使用GLSurfaceView的重叠组合来制作热图(如果您不知道热图是什么,请不要担心)和SurfaceView一起进行轴标记,热图顶部的位图等。这样GLSurfaceView可以做它擅长的事情,基于画布的SurfaceView可以做它擅长的事情。 SurfaceView具有透明背景,因此可以通过它看到GLSurfaceView。
我的问题是GLSurfaceView在渲染时似乎出现在“顶部”,我无法使用“bringToFront()”方法强制SurfaceView返回顶部。有没有办法做到这一点?我已经关闭了连续渲染,所以当我渲染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();
}
显然这不是所有的代码 - 我试图展示最相关的部分。关于如何将SurfaceView(辅助)放在最上面的任何想法?