【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
- 【Android开发学习40】在GLSurfaceView之上添加SurfaceView层
- 在GLSurfaceView之上添加SurfaceView层
- 【Android开发学习39】VideoView在GLSurfaceView之上显示的解决方案
- android view surfaceView GLSurfaceView
- 【Android游戏开发】追加简述SurfaceView 与 GLSurfaceView效率!
- Android游戏开发之View SurfaceView GLSurfaceView视图
- Android游戏开发学习(5)--实现Button悬浮于与SurfaceView之上
- Android学习笔记(一)——surfaceview、GLSurfaceview
- 层在flash之上
- android view,surfaceview,glsurfaceview的区别
- android中view surfaceView GLSurfaceView的区别
- Android多媒体之view,SurfaceView,GLSurfaceView
- 【Android游戏开发二十六】追加简述SurfaceView 与 GLSurfaceView效率!
- (转)【Android游戏开发二十六】追加简述SurfaceView 与 GLSurfaceView效率!
- 【Android游戏开发二十六】追加简述SurfaceView 与 GLSurfaceView效率!
- 【Android游戏开发二十六】追加简述SurfaceView 与 GLSurfaceView效率!
- 浮动层在flash之上
- 【Android游戏开发之六】在SurfaceView中添加组件!!!!并且相互交互数据!!!!
- muysql bigint转换为date, 字段值比较
- ╮(╯▽╰)╭
- hdu 3371 Connect the Cities(最小生成树)
- ext.js 4.1 的 combo 的forceSelection 属性遇到BUG
- 架构师的大局观
- 【Android开发学习40】在GLSurfaceView之上添加SurfaceView层
- LibGDX QQ群建立,欢迎对libGDX有兴趣的程序员加入。
- 聚簇索引(Clustered Index)和非聚簇索引 (Non- Clustered Index)举例说明
- mysqldump:常用操作、案例分享、意外终止的原因以及解决方法
- H.264 Profile
- 深入理解C++中关键字 mutable
- 用C语言写CGI
- 第五次课堂作业
- 开发者如何提升和推销自己