2010-09-12 51 views
0

我正在写一个android应用程序,并且在其中我想要有一个标题栏,包括游戏名称,分数等等。然后在下面我想要一个图像视图的网格,这将有点像我可以在游戏中显示不同角色的瓦片。Android版面不能正常显示

我有以下XML布局,但是当我运行它,我得到一个黑色的屏幕:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

    <TextView android:id="@+id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text="@string/app_name" 
      /> 
    <TextView android:id="@+id/score" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text="@string/score" 
      /> 
    <TextView android:id="@+id/score" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text="0" 
      /> 
    <TextView android:id="@+id/robotsLeft" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text="@string/robots" 
      /> 
    <TextView android:id="@+id/score" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text="0" 
      /> 

</LinearLayout> 

<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gridview" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:columnWidth="90dp" 
    android:numColumns="auto_fit" 
    android:verticalSpacing="10dp" 
    android:horizontalSpacing="10dp" 
    android:stretchMode="columnWidth" 
    android:gravity="center" 
/> 

GridView控件初始化为每本教程:

http://developer.android.com/resources/tutorials/views/hello-gridview.html

即。在我的主要活动onCreate():

super.onCreate(savedInstanceState); 
setContentView(R.layout.main);   
GridView gridview = (GridView) findViewById(R.id.gridview); 
gridview.setAdapter(new ImageAdapter(this)); 

任何人都可以看到我做错了什么吗?

谢谢!

回答

2

那么,这是无效的XML,因为没有根元素。此外,您所有的TextView小工具都有android:layout_height="fill_parent",这很奇怪。你也可以考虑使用hierarchyviewer来更仔细地检查你的布局,看看还有什么可能会出错。

+0

感谢您的回答,我只是愚蠢的,并有我的游戏循环开始形式onCreate(),但布局直到onCreate()后才呈现我猜?无论如何,通过使我的班级与游戏循环解决Runnable – Kalypso 2010-09-12 19:59:18

+0

@Kalypso解决方案:正确 - 直到您将控制权交还给Android,您的用户界面将不会呈现。 – CommonsWare 2010-09-12 20:11:02

0

您应该在它们下方放置一个(线性)布局,因为您的xml无效。