使用 SurfaceView 时不显示按钮
我的游戏循环类是从 SurfaceView 扩展的。 当我尝试以编程方式或通过 XML 添加按钮时,它不会显示 - 我在网上多次看到这个问题,但没有找到合适的解决方案。有些人建议将 SurfaceView 夹在 FrameLayout 中,但这没有什么区别。
我很惊讶越来越多的人在游戏中不使用常规按钮,所以这个问题还没有得到彻底的回答。
这是我的 XML:(引擎 = 扩展表面视图的游戏类)
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.game.test.Engine
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</com.game.test.Engine>
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<Button
android:id="@+id/btnReset"
android:layout_width="80dp"
android:layout_height="40dp"
android:text="Reset"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:textColor="#FFFFFF"
android:background="@drawable/custom_button"
></Button>
</LinearLayout>
My gameloop class is extended from a SurfaceView.
When I try to add a Button either programmaticly or thru XML it is not displayed - I have seen this question asked various times on the net but have found no suitable solutions. Some people have suggested sandwiching the SurfaceView in a FrameLayout but it has made no difference.
I'm surprised more people aren't using regular Buttons in their games and so this question hasn't been answered to death.
Here is my XML: (Engine = Game class that extends a surfaceview)
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.game.test.Engine
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</com.game.test.Engine>
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<Button
android:id="@+id/btnReset"
android:layout_width="80dp"
android:layout_height="40dp"
android:text="Reset"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:textColor="#FFFFFF"
android:background="@drawable/custom_button"
></Button>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也看到了这个问题....稍微玩了一下,我注意到如果我将布局中的按钮“夹在”SurfaceView 之上,则会显示按钮...但是如果按钮位于下面SurfaceView,它不显示。因此,如果您不介意按钮位于 SurfaceView 上方,那么应该没问题。我希望我的按钮位于 SV 下面,所以我仍在寻找更好的解决方案......
I am also seeing this problem....playing around with it a bit, I noticed that if I 'sandwich' the button in a layout to be ABOVE the SurfaceView, the button is displayed....but if the button is below the SurfaceView, it is not displayed. So if you don't mind your button to be above the SurfaceView, you should be OK. I would prefer my buttons to be below the SV, so I'm still looking for a better soluton...