SetContentView不显示R.layout.main只有glSurfaceView

时间:2012-06-25 10:38:39

标签: macos opengl surfaceview

我有一个实现OpenGL的程序,而glSurfaceView是根布局(相对布局)。当我调用public void onCreate(Bundle savedInstanceState)函数时,我只能从OpenGL中获取绘图,而且我没有获得其他布局。为什么会这样? 这是我的代码:

包com.reea.red;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.View;

  public class AvatarCreator extends Activity {
/** Called when the activity is first created. */
private static int tab=3;
private GLSurfaceView glSurfaceView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    glSurfaceView = new GLSurfaceView(this);
    // set our renderer to be the main renderer with
    // the current activity context
    glSurfaceView.setRenderer(new GlRenderer(this));
    setContentView(R.layout.main);
    setContentView(glSurfaceView);
   // findViewById(R.id.linearLayout1).setVisibility(View.VISIBLE);


    //setContentView(R.layout.main);
}

public static int getTab() {
    return tab;
}

public static void setTab(int tab) {
    AvatarCreator.tab = tab;
}

}

1 个答案:

答案 0 :(得分:1)

我设法使用此代码:

super.onCreate(savedInstanceState);


    setContentView(R.layout.main);

    final GridView gridview = (GridView) findViewById(R.id.gridView1);
    final ImageAdapter adapter=new ImageAdapter(this);

    mGLView = (GLSurfaceView)findViewById(R.id.glSurface); 

    mGLView.setEGLConfigChooser(8,8,8,8,16,0);

    mGLView.setRenderer(new HelloOpenGLES10Renderer(this));
    mGLView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    mGLView.setZOrderOnTop(true);

    this.mGLView = (GLSurfaceView) this.findViewById(R.id.glSurface);