GLSurfaceView中添加button组件(示例是多activity中,使用openGL画一彩色旋转立方体)

添加下面几行代码可以在GLSurfaceView中增加一个Button按钮
Button b =   new   Button(   this );
b.setText(   "hello world" );
this .addContentView(b,   new   LayoutParams(LayoutParams. WRAP_CONTENT   ,LayoutParams. WRAP_CONTENT ));



示例:
public class openGLActivity extends Activity {
      
      
       //private openGLRender Render;
      
       public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      this.requestWindowFeature(Window. FEATURE_NO_TITLE); // (NEW)
        getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN,
            WindowManager.LayoutParams. FLAG_FULLSCREEN); // (NEW)
       
        Log. i("openGLActivity", "onCreate()");

            GLSurfaceView view = new GLSurfaceView(this);
             final openGLRender Render = new openGLRender();
            view.setRenderer(Render);
            setContentView(view);
            
            Button b = new Button(this);
            b.setText( "hello world");
            this.addContentView(b, new LayoutParams(LayoutParams.WRAP_CONTENT ,LayoutParams.WRAP_CONTENT));

            
            view.setOnClickListener( new OnClickListener()
            {
                   public void onClick(View v)
                  {
                        Render.onClick(v);
                  }
            });
                  
      
      }

}

你可能感兴趣的:(button)