更改布局而不影响活动中的背景视图
我是 Android 编程新手,在以下方面遇到了一些问题。
我正在尝试为游戏制作一个菜单,并且我希望在后台运行一个 OpenGL 视图(带有游戏的运行演示),然后让各种菜单屏幕在此之上发生变化;无需重新加载或影响 OpenGL 视图。
乍一看,我有两种方法可供选择:第一种为每个屏幕使用单独的活动,然后从 xml 布局加载每个单独的菜单。这显然会为每个活动重新加载 OpenGL 视图的新实例。第二种选择是使用单个活动并根据请求扩展每个 XML 布局,使 OpenGL 视图运行不变。
如果可能的话,我想使用第一种方法,但如上所述,加载新活动时所有视图都会结束。我认为第二种方法应该可行 - 但随后我将整个菜单的所有代码都放在一个文件中。我很确定我错过了一些东西。
如果有人可以为此推荐最佳方法,我们将不胜感激。
谢谢。
PS - 我想期望的结果类似于《愤怒的小鸟》菜单,其背景中有不断滚动的风景。
I'm new to android programming and I'm having a little trouble with the following.
I'm trying to make a menu for a game, and I'd like to have an OpenGL view running in the background (with a running demo of the game) and then have the various menu screens change over the top of this; without reloading or affecting the OpenGL view.
At first glance it appears I have a choice of two methods: the first to use separate activities for each screen and then load each individual menu from xml layouts. This obviously reloads a new instance of the OpenGL view per activity. The second option would be to use a single activity and inflate each XML layout on request, leaving the OpenGL view running untouched.
If possible I'd like to use the first method, but as stated all the views end when a new activity is loaded. The second method I think should work - but then I have all the code for the entire menu in a single file. I'm pretty sure I'm missing something.
If anyone can recommend the best approach for this it would be appreciated.
Thanks.
P.S - I guess the desired result is that similar to the Angry Birds menu which has the continually scrolling landscape in the background.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用片段。您可以保留一个 Activity(否则您必须为每个 Activity 重新初始化 openGL),然后在您的 openGL 内容上弹出不同的片段。
Use Fragments. You can keep one Activity (you'd have to re-initialise openGL for each activity otherwise), and then have different fragments pop up over your openGL stuff.