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

来源:互联网 发布:java poi 导出excel 编辑:程序博客网 时间:2024/05/19 05:32

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;@Overrideprotected 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 imagebuttonsLayoutInflater 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

 

 

 

 

原创粉丝点击