Joh*_* D. 10 height android listview tablelayout
我在LinearLayout中有这个ListView:
<?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>
Run Code Online (Sandbox Code Playgroud)
List由SimpleCursorAdapter以编程方式填充:
adapter = new SimpleCursorAdapter(this, R.layout.list_row_search, mCursor, from, to);
Run Code Online (Sandbox Code Playgroud)
list_row_search有一个带有两个TableRows的TableLayout:
<?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>
Run Code Online (Sandbox Code Playgroud)
现在,当列表被填充时,即使在数据库中只找到一个元素,ListView也占据了空洞屏幕.eclipse中的HierarchyView显示非常清楚,ListView是填充屏幕的那个.
你能说出问题出在哪里吗?谢谢你的时间!
Kar*_*uri 14
你不应该使用wrap_content
a的高度ListView
.wrap_content
意思是"让我尽可能地拥抱我所有的孩子." 如果您认为您的数据集可能非常大,那听起来应该是个糟糕的主意.由于您使用的是LinearLayout,请提供ListView layout_height="0dp"
和 layout_weight="1"
.
让它ListView
拍摄屏幕的其余部分是可以的.如果它只有一行,它将显示一行,没什么大不了的.除非你试图在列表下方显示某些内容,但我上面告诉你的内容应该可以实现.
归档时间: |
|
查看次数: |
13215 次 |
最近记录: |