我试图在我的GLSurfaceView上添加像android.widget.Button这样的android小部件。但是如果我这样做,GLSurfaceView会变成全黑的
以下是我用来做这样的事情的代码:
mGLView = new MyGLSurfaceView(this);
Button b = new Button(this);
b.setText("Hello World");
setContentView(mGLView);
addContentView(b, new LayoutParams(60, 60));//comenting this
//line makes GLSurfaceView work as expected
我也尝试在布局上同时使用它们,并且发生了同样的问题。
答案 0 :(得分:0)
我设法通过评论这行代码来实现它的工作
class MyGLSurfaceView extends GLSurfaceView {
private final MyGLRenderer mRenderer;
public MyGLSurfaceView(Context context) {
super(context);
//setLayerType(View.LAYER_TYPE_HARDWARE, null); << this line
setEGLContextClientVersion(2);
mRenderer = new MyGLRenderer();
setRenderer(mRenderer);
setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
}
public boolean touchEvent(MotionEvent e) {
if (mRenderer.scene != null) {
mRenderer.scene.control.onTouchEvent(e);
mRenderer.scene.onTouchEvent(e);
}
return false;
}
}