在活动中使用GlSurfaceview
我有一个 Activity,并且我已将 Activity 的内容视图设置为“R.layout.main.xml”。我还有另一个类,其中包含使用 openGL 创建的动画。现在我需要在活动的背景中使用这个动画。
代码是这样的
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_pixie);
mGLView = new ClearGLSurfaceView(this);
setContentView(mGLView);
}
但是我的应用程序崩溃了..我该如何解决这个问题。
I have an Activity and i had set activity's content view as "R.layout.main.xml".And i have an another class which contains animation created using openGL. Now i need to use this animation in the background of the Activity.
The code is like this
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_pixie);
mGLView = new ClearGLSurfaceView(this);
setContentView(mGLView);
}
But my app is Crashing ..How can i solve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您第二次调用
setContentView()
时,您将替换第一次设置的内容,只留下背景。崩溃很可能是因为您依赖于主布局中的元素,而这些元素已被删除。您应该在主布局中包含
GLSurfaceView
,而不是调用setContentView()
两次。下面是如何完成此操作的示例:然后您可以像往常一样在
onCreate()
中加载此布局(main_pixie_new 指的是上面的 xml,我只是给它起了这个名称以保持清晰尽可能):When you call the
setContentView()
a second time, you replace what had been set the first time, leaving you with only the background. The crash is most likely because you depend on the elements in the main layout, which is removed.Rather than calling
setContentView()
twice, you should include theGLSurfaceView
in the main layout. Below is an example of how this can be done:Then you can load this layout in your
onCreate()
as usual (main_pixie_new refers to the above xml, I just gave it that name to keep things as clear as possible):