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
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="@drawable/cimov"
- android:gravity="center"
- >
- </LinearLayout>
4.imagebutton.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal" android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:layout_weight="2">
- <EditText
- android:id="@+id/setup_hostip_edit"
- android:paddingLeft="100dp"
- android:layout_width="100dp"
- android:layout_height="50dp"
- android:layout_gravity="bottom"
- android:textSize="20sp"
- android:paddingBottom="8dp"
- android:singleLine="true"
- android:editable="true"
- />
- <ImageButton android:id="@+id/button1" android:src="@drawable/icon"
- android:paddingLeft="100dp"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:layout_gravity="bottom" android:background="@null" />
- <ImageButton android:id="@+id/button2" android:src="@drawable/icon"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:layout_gravity="bottom" android:background="@null" />
- <ImageButton android:id="@+id/button3" android:src="@drawable/icon"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:layout_gravity="bottom" android:background="@null" />
- <ImageButton android:id="@+id/button4" android:src="@drawable/icon"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:layout_gravity="bottom" android:background="@null" />
- <Button android:id="@+id/button5" android:src="@drawable/icon"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:layout_gravity="bottom" android:background="@null" />
- </LinearLayout>
5.拓展说明:
在某些资料资料中,有使用FrameLayer来布局的,先添加GLSurfaceView,再添加SurfaceView,也是一样的。
http://blog.csdn.net/ypist/article/details/8810335