Android ListActivity - 如何在ListView下方添加一个视图?

9
我正在尝试在ListActivity的ListView下方放置一个ProgressBar视图。我希望它始终在最后一行下面。
ProgressBar位于LinearLayout中,只要列表(由运行时适配器填充)不超过屏幕,它就会显示出来。一旦列表大于屏幕,ProgressBar将不再可见。
布局xml如下:
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/db1_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<!-- Title bar -->
<LinearLayout
    style="@style/TitleBar" >
    <TextView
        style="@style/TitleBarText"
        android:text="Some title text" />
    <ImageButton
        style="@style/TitleBarAction"
        android:contentDescription="@string/description_search"
        android:src="@drawable/title_search" />
</LinearLayout>

<!--  Content -->
<LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" >

    <ListView
        android:divider="@drawable/category_item_divider"
        android:dividerHeight="@dimen/list_divider_height"
        android:layout_height="wrap_content"
        android:id="@+id/android:list"
        android:layout_width="fill_parent"
        android:layout_weight="1" />        
    <TextView
        android:id="@+id/android:empty"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="@string/category_no_items" />                 
</LinearLayout>     

<!--  Progress bar -->
<LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="wrap_content" >

    <ProgressBar
        android:id="@+id/productlist_progressbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout> 

</LinearLayout>

使用LinearLayout无法实现这个吗?需要任何帮助。


页脚随着列表视图滚动,如果您希望视图固定在屏幕底部,在列表视图下方设置权重即可。 - urSus
1个回答

12

您应该使用以下代码添加页脚:

list.addFooterView(footerView);

如果你要手动完成布局,请考虑使用相对布局,其比线性布局更加强大。然后将页脚放置在列表下方,或者更好的是,将列表空视图都放置在页脚上方。


谢谢,页脚视图正是我所需要的。现在唯一的小问题是,我已经在我的ListView中设置了android:divider,当我将footerView设置为visibility=GONE(仅在加载更多数据时使用)时,底部会出现两个分隔线。猜想这没有“解决办法” :-) - Bachi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接