簡體   English   中英

Android布局無法正確顯示

[英]Android layout not showing properly

我正在編寫一個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));

誰能看到我做錯了什么?

謝謝!

嗯,那是無效的XML,因為沒有根元素。 另外,您所有的TextView小部件都具有android:layout_height="fill_parent" ,這很奇怪。 您可能還考慮使用hierarchyviewer來更仔細地檢查您的布局,看看還有什么地方出了問題。

您應該在其下放置(線性)布局,因為xml無效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM