我启动了一个
Android OpenGL应用程序,我有以下类:
- class A extends Activity
- class B extends GlSurfaceView implements Renderer
当调用类A的onCreate时,它会创建一个类B类的对象并调用:
- setContentView(Bobject)
到目前为止它工作,我花了几天时间.
现在我想在我的应用程序中添加按钮并找到SurfaceViewOverlay示例.这使用一些XML来创建视图层次结构.我想创建一些非常类似于我简单剪切和粘贴XML代码的东西:
- <android.opengl.GLSurfaceView android:id="@+id/glsurfaceview"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
- <LinearLayout android:id="@+id/hidecontainer"
- android:orientation="vertical"
- android:visibility="gone"
- android:background="@drawable/translucent_background"
- android:gravity="center"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- ...
现在请记住我原来的类层次结构,如何初始化我的视图?我应该在A班的onCreate()中写什么?
我试过用:
- Bobject = new B(this);
- GLSurfaceView glSurfaceView =
- (GLSurfaceView) findViewById(R.id.glsurfaceview);
- glSurfaceView.setRenderer(Bobject);
它确实在屏幕上绘制按钮和GL视图,但GL视图无法从点击/点击中获取任何输入.
这可能是因为Bobject的onTouchEvent()没有被调用,因为它只被用作:
- Renderer
而不是:
- glSurfaceView
宾语.
而不是上面的代码,我真正想要的是让Bobject取代glSurfaceView.但我不知道该怎么做.当我找到FindById()时,似乎已经创建了glSurfaceView.如何让它在GL视图中使用B类对象?
抱歉任何新手的错误.完全是Android新手.
编辑:我也试过这个:
我也尝试过以下方法:
在我的XML文件中,我将GLSurfaceView更改为:
- <com.bla.bla.B
- android:id="@+id/glsurfaceview"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
- // This returns null
- Bobject = (B) findViewById(R.id.glsurfaceview);
- // And this suspends the application. :(
- setContentView(R.layout.surface_view_overlay);