在 SurfaceView 上渲染按钮
我一直在谷歌上寻找如何做到这一点,从我收集到的信息来看,它并不像 123 那么容易,因为表面视图只会在它上面绘制,人们所说的解决方案是使用 xml 布局并制作一个布局,然后将表面视图添加为子视图,将按钮添加为子视图。然而,我完全迷失了这一点,我真的很想看到一些关于如何做到这一点的代码(我更喜欢查看示例和反复试验来学习)。
我的 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">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/Menu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Menu" />
<Android.Game.GameView
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout>
</LinearLayout>
除了您在 xml 上看到的内容之外,没有任何代码可以添加到按钮中(我一直在进行大量的试验和错误)。
项目的工作方式如下:活动 --> setContentView(表面视图) -->在 onDraw 上渲染 gfx
有人可以帮我吗,一旦我看到了如何使用 1 个对象执行此操作的示例,我将能够使用其他对象执行此操作。
编辑-解决了它 好的,我已经成功地从这篇文章中解决了这个问题 http:// /www.mail-archive.com/[email protected]/msg11780.html
我必须将内容视图设置为xml 文件,并向表面视图添加一些构造,以便它可以工作
I've been looking on google on how to do this, from what I've gathered it's not as easy as 123 because the surface view will just draw above it, the solution which people have said is to use an xml layout and make a layout and then add the surface view as a child and the button as a child to that. However I'm completely lost on this I'd really love to see some code on how to do this (I prefer looking at examples and trial and error for learning).
My xml file
<?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">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/Menu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Menu" />
<Android.Game.GameView
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout>
</LinearLayout>
I've got no code for adding in the button except for what you see on the xml (I've been doing a lot of trial and error).
project works like this: activity --> setContentView(surface view) --> render the gfx on the onDraw
Can someone please help me with this, once I've seen an example on how to do this with 1 object I'll be able to do it with other objects.
EDIT - solved it
o.k I've managed to work it out from this post http://www.mail-archive.com/[email protected]/msg11780.html
I had to set the content view to the xml file, and add some constructs to the surface view so it would work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我必须做一些类似的事情来在
SurfaceView
的顶部显示ImageView
,并按如下方式进行:这会导致按钮浮动在 SurfaceView 的顶部右下角。
I had to do something similar to display an
ImageView
over-top of aSurfaceView
, and did it as follows:This results in the button floating over top of the SurfaceView on the bottom-right corner.