在 SurfaceView 上覆盖 Android 布局
我正在设计一个简单的 Android 游戏,使用类似于 Google 提供的 Lunar Lander 示例的 SurfaceView。我希望在屏幕上弹出各种内容,例如高分、消息、菜单等,而表面视图仍然在后台。
问题是我希望“弹出窗口”包含许多设计元素,例如图像、文本框等。有没有一种方法可以在 XML 中创建布局来设计我想要的弹出窗口,然后将其显示在表面视图上一个对象,而不是必须在代码中一一构造每个单独的元素并将它们全部绘制到画布上?
我想从屏幕一侧对弹出窗口进行动画处理,因此如果我用 XML 设计布局,以便所有对象都知道它们之间的关系,然后将该布局作为一个对象进行动画处理,那就太好了。
我觉得这很简单,但我似乎找不到如何实现它。
I am designing a simple Android game using a surfaceview similar to the Lunar Lander sample provided by Google. I want to have various things such as highscores, messages, menus etc pop up on screen with the surface view still in the background.
The problem is that I want the "pop ups" to contain many design elements such as images, textboxes etc. Is there a way that I can create a layout in XML to design the pop up I want and then display that over the surfaceview as one object rather than having to construct each individual element one by one in code and paint them all to the canvas?
I want to animate the pop ups in from the side of the screen, so it would be good if I design the layout in XML so that all the object know their relation to each other and then animate that layout as one object.
It strikes me as something quite simple but I just cant seem to find how to achieve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在代码或 XML 布局中将元素覆盖在 SurfaceView 之上。
在您的活动中:
但不知道性能问题。
You can overlay elements on top of SurfaceView either in code or in your XML layouts.
And in your Actiivty:
Don't know about the performance issues though.
执行此操作的一个简单方法是将弹出界面创建为不同的活动。然后,您可以在清单文件中为其指定透明背景主题,例如对话框主题。
查看 API 演示中的 CustomDialog、Translucent 和 TranslucientBlur 示例。他们创造了这样的活动。底层活动位于表面这一事实不应改变任何事情。
A simple way of doing this is creating your popup interface as a different Activity. You would then give a transparent background theme to it, like the Dialog theme, in your manifest file.
Look at the CustomDialog, Translucent and TranslucientBlur samples in API Demos. They create such activites. The fact that the underlying activity is in a surface shouldn't change anything.