ListView的高度填满整个屏幕,虽然设置为WRAP_CONTENT [英] Height of ListView fills the whole screen, although set as wrap_content

查看:655
本文介绍了ListView的高度填满整个屏幕,虽然设置为WRAP_CONTENT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的ListView中的LinearLayout内:

i have this ListView inside a LinearLayout:

<?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>

列表中编程居住着一个S​​impleCursorAdapter:

The List is populated programmatically by a SimpleCursorAdapter:

adapter = new SimpleCursorAdapter(this, R.layout.list_row_search, mCursor, from, to);

list_row_search有两个TableRows一个TableLayout:

list_row_search has a TableLayout with two 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>

现在,当名单被填充,ListView中占据了孔筛,哪怕只有一个元素被发现在数据库中。在Eclipse中HierarchyView显示pretty的明确,那ListView控件是一个充满了屏幕。

Now when the list gets populated, the ListView occupies the hole screen, even if only one element was found in the database. The HierarchyView in eclipse shows pretty clear, that the ListView is the one that fills out the screen.

你能知道的,问题出在哪里?感谢您的时间!

Can you tell, where the problem is? Thanks for your time!

推荐答案

您不应该使用 WRAP_CONTENT 的ListView <高度/ code>。 WRAP_CONTENT 的意思是使我一样大,需要容纳所有我的孩子。当你考虑你的数据集可能会可能非常大,这应该听起来像pretty的坏主意。 由于您使用的是LinearLayout中,给你的ListView layout_height =0dp layout_weight =1

You shouldn't use wrap_content for the height of a ListView. wrap_content means "make me as large as needed to hold all of my children." When you consider that your data set could be potentially very large, that should sound like a pretty bad idea. Since you are using a LinearLayout, give your ListView layout_height="0dp" and layout_weight="1".

没关系,让的ListView 走在屏幕的其余部分。如果它只有一个行,它会显示一个行,没什么大不了的。除非你想显示下面的列表的东西,但我上面告诉你应该做到这一点。

It's okay to let the ListView take the remainder of the screen. If it only has one row, it will show one row, no big deal. Unless you are trying to show something below the list, but what I've told you above should accomplish that.

这篇关于ListView的高度填满整个屏幕,虽然设置为WRAP_CONTENT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆