我有這樣的ListView一個的LinearLayout裏面:高度的ListView填滿整個屏幕,雖然設置爲WRAP_CONTENT
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
.../>
<EditText />
...
</EditText>
<ListView
android:id="@+id/words_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
名單由SimpleCursorAdapter編程填充:
adapter = new SimpleCursorAdapter(this, R.layout.list_row_search, mCursor, from, to);
list_row_search有一個TableLayout與兩個TableRows:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<View
android:layout_height="1dip"
android:background="#FF33B5E5" />
<TableRow
android:id="@+id/tableRow1"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/list_lesson"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="1dip"
android:textSize="12sp" />
<TextView
android:id="@+id/list_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5.25"
android:padding="1dip"
android:paddingRight="10dp"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/list_flex"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="12.5"
android:padding="1dip"
android:paddingRight="10dp" />
<TextView
android:id="@+id/list_rom"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="6.25"
android:padding="1dip"
android:paddingRight="10dp" />
</TableRow>
<View
android:layout_height="0.1dip"
android:background="#404040" />
<TableRow
android:id="@+id/tableRow2"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/list_related"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:paddingRight="10dp"
android:textStyle="italic" />
<TextView
android:id="@+id/list_ant"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="10dp" />
<TextView
android:id="@+id/list_engl"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="10dp" />
</TableRow>
<View
android:layout_height="1dip"
android:background="#FF33B5E5" />
</TableLayout>
現在,當列表被填充,L即使在數據庫中只找到一個元素,istView也會佔據洞屏幕。 eclipse中的HierarchyView顯示非常清晰,ListView是填充屏幕的那個。
你能告訴,問題在哪裏?謝謝你的時間!
感謝您的回答,但將高度從「wrap_content」更改爲0dp/weight = 1會導致相同的行爲:ListView會填滿整個屏幕。實際上,我試圖在列表下方顯示一些內容,但是僅顯示一個元素(當發現一個元素時)的整個列表視圖讓我把下面的列表放入... – 2013-03-18 15:50:25
您仍然可以給它height = 0和weight = 1。在它之後添加另一個視圖,並且LinearLayout將爲該項目分配空間並將剩餘部分給予ListView。如果你試圖讓一個固定在列表底部的項目,但滾動列表的內容,你想看看'ListView.addFooterView()' – Karakuri 2013-03-19 14:36:36