Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – ListView的高度填充整个屏幕,虽然设置为wrap_content大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个ListView里面的LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://scheR_807_11845@as.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://scheR_807_11845@as.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显示很清楚,ListView是填充屏幕的.

你能说出问题在哪里?谢谢你的时间!

解决方法

您不应该使用wrap_content作为ListView的高度. wrap_content意味着“让我尽可能的大,以保持我所有的孩子”.当您认为您的数据集可能非常大时,这听起来应该是个不错的主意.
由于您使用的是LinearLayout,您可以将ListView layout_height =“0dp”和layout_weight =“1”.

可以让ListView取屏幕的其余部分.如果只有一行,它会显示一行,没有什么大不了的.除非你试图在列表下方显示某些内容,否则我以前告诉过你应该做到这一点.

大佬总结

以上是大佬教程为你收集整理的android – ListView的高度填充整个屏幕,虽然设置为wrap_content全部内容,希望文章能够帮你解决android – ListView的高度填充整个屏幕,虽然设置为wrap_content所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。