0

我对 Android 编程很陌生,所以这可能是非常基本的东西。我只有一个带有几个按钮的 xml 布局。我正在尝试遵循 JetBoy 演示给出的模型,因此我正在向扩展 SurfaceView 的布局添加一个视图。当这个新视图放在我的 xml 布局中时,我只是得到一个空白屏幕。

如果有帮助,这里是 XML 布局。gameview 元素是导致屏幕空白的原因

<?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"
    android:alwaysDrawnWithCache="true">
 <game.test.gameEngine
      android:id="@+id/gameView"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"/>
<Button android:text="Easy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/EasyButton"></Button>
<Button android:text="Medium" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/MedButton"></Button>
<Button android:text="Hard" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/HardButton"></Button>
<DatePicker android:id="@+id/DatePicker01" android:layout_width="wrap_content" android:layout_height="wrap_content"></DatePicker><Button android:id="@+id/Button04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Exit"></Button>


</LinearLayout>
4

2 回答 2

2

什么是game.test.gameEngine?它是否扩展了 View 类?如果是这样,它会占据整个屏幕。您将宽度和高度都设置为“fill_parent”,这意味着按钮和日期选择器不在屏幕上。如果您希望按钮显示在游戏引擎视图的顶部,那么您必须将按钮设置为游戏引擎的子项,或者您必须将高度和宽度设置为可为按钮留出空间的值.

嵌入和排列视图可能很难学习,也很复杂,所以我建议寻找与您正在做的类似的代码示例,以及浏览 google 在其网站上发布的教程。

于 2010-06-05T22:18:23.963 回答
1

如果您打算在主游戏视图中使用其他东西(例如顶部的按钮),我绝对建议您研究相对布局。我以这种方式完成了 GLSurfaceView,并且效果很好。

相对布局的一般思想是,在没有给出任何布局参数的情况下,给定的每个视图都绘制在左上角。但是,当被告知要对齐父视图中的某处或旁边(左/右,或上方/下方)另一个视图时,您可以控制事物出现的位置。

还需要注意的是,列出的每个新视图都显示在另一个之上(如果未对齐),因此您首先列出主表面游戏视图,然后列出按钮。

于 2010-06-06T01:51:05.637 回答