【Android开发学习40】在GLSurfaceView之上添加SurfaceView层

1. 首先,初始化系统:

rivate void sys_init(){
	// 去掉标题栏
	requestWindowFeature(Window.FEATURE_NO_TITLE);
	
	// 全屏
	getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN ,  
				  WindowManager.LayoutParams.FLAG_FULLSCREEN);
	
	setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);		//强制为横屏
	//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);	//强制为竖屏
	
	// 获取屏幕的分辨率
	screenWidth  = getWindowManager().getDefaultDisplay().getWidth();       // 屏幕宽(像素,如:480px)   
	screenHeight = getWindowManager().getDefaultDisplay().getHeight();      // 屏幕高(像素,如:800p)
	normalLayerZ = -((float)screenHeight/2.0f); 
	System.out.println("screenWidth=" + screenWidth + "; screenHeight=" + screenHeight);  		
}


 

2.主函数入口的onCreate函数实现:

MainMenu mainMenu;
MySurfaceView mGLSurfaceView;

LinearLayout imageButtonLinearLayout;
ImageButton mytestButton;
ImageButton mytestButton2;

@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	sys_init();
	setContentView(R.layout.main);
	
	/* -------------------- Start add ImageButtons------------------------------------- */
	Context context = this.getApplicationContext();
	imageButtonLinearLayout = new LinearLayout(this);
	imageButtonLinearLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
	imageButtonLinearLayout.setOrientation(LinearLayout.VERTICAL);
	// add imagebuttons
	LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	LinearLayout imagebuttonLinearLayout = (LinearLayout) inflater.inflate(R.layout.imagebutton, imageButtonLinearLayout, false);
	imageButtonLinearLayout.addView(imagebuttonLinearLayout);
	/* -------------------- End add ImageButtons------------------------------------- */
	
	mGLSurfaceView=new MySurfaceView(MainActivity.this);
	mGLSurfaceView.requestFocus();//获取焦点
	mGLSurfaceView.setFocusableInTouchMode(true);//设置为可触控
	gn_DB_type=dCimovDbType_Singer;
	
	mGLSurfaceView.setZOrderOnTop(true);	// 置到Top层
	mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSPARENT);	// 设置背景为透明
	
	// 添加3D SurfaceView (GLSurfaceView)
	setContentView(mGLSurfaceView);
	
	// 添加imageButtonLinearLayout (SurfaceView)
	addContentView(imageButtonLinearLayout, new LayoutParams(LayoutParams.FILL_PARENT,
			LayoutParams.FILL_PARENT));
	
	// 添加SurfaceView上的按钮响应事件
	mytestButton=(ImageButton)findViewById(R.id.button1);
	mytestButton.setOnClickListener(CimovSysBtnClickListen); 
	
	mytestButton2=(ImageButton)findViewById(R.id.button2);
	mytestButton2.setOnClickListener(CimovSysBtnClickListen); 
}

 


3.main.xml




    

 


4.imagebutton.xml




	
	
	
	
	
	
	


 

 

5.拓展说明:

  在某些资料资料中,有使用FrameLayer来布局的,先添加GLSurfaceView,再添加SurfaceView,也是一样的。

 

 

 

 

本文博客源地址:http://blog.csdn.net/ypist

 

 

 

 

你可能感兴趣的:(Android应用开发,OpenGL)