views:

408

answers:

2

I'm very new to Android programming, so this is probably something pretty basic. I just have an xml layout with a few buttons. I'm trying to follow the model given by the JetBoy demo, so I'm adding a view to the layout which extends SurfaceView. When this new view is put in my xml layout, I just get a blank screen.

Here's the XML layout if it helps. The gameview element is what causes the screen to be blank

<?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>
+1  A: 

what is game.test.gameEngine? Does it extend the View class? If so, it is taking up the entire screen. you have both width and height set to "fill_parent", which means that the buttons and datepicker are off the screen. If you want the buttons to appear on top of the game engine view, then you will have to either set the buttons as children of the game engine, or you will have to set the height and width to values that will leave space for the buttons.

embedding and arranging views can be difficult and complicated to learn, so i would suggest looking for code examples similar to what you are doing, as well as browsing the tutorials posted by google on their site.

mtmurdock
+1  A: 

I would absolutely suggest looking into a Relative Layout if you're intending on having a main game view with other things like buttons on top. I have a GLSurfaceView done this way and it works very well.

The general idea with a Relative Layout, is that without any layout parameters given, each view given is drawn in the upper left. However, when told to be aligned somewhere in the parent or next to (to the left/right of, or above/below) another view you can control where things appear.

It's also good to note that each new view listed appears on top of the other (if not aligned otherwise) so you'd list the main surface game view first and the buttons after it.

Maximus