简体   繁体   English

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

[英]Android ListActivity - how to add a view below the ListView?

I'm trying to put a ProgressBar view below a ListView for a ListActivity.我正在尝试在 ListActivity 的 ListView 下方放置一个 ProgressBar 视图。 I want it to be always below the last row in the listView.我希望它始终位于 listView 的最后一行下方。

The ProgressBar, which is placed in a LinearLayout, does appear, as long as the list (which is filled by an adapter at runtime) is not exceeding the screen.只要列表(在运行时由适配器填充)不超过屏幕,就会出现放置在 LinearLayout 中的 ProgressBar。 As soon as the list is larger than the screen, the ProgressBar is no longer visible.一旦列表大于屏幕,ProgressBar 就不再可见。

The layout xml looks like this:布局 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>

Is this not possible with a LinearLayout?这对于 LinearLayout 是不可能的吗? Any help appreciated.任何帮助表示赞赏。

You should add a footer using:您应该使用以下方法添加页脚:

list.addFooterView(footerView);

or doing it manually, but then consider using relative layouts, there are far more powerfull than linear layouts.或手动执行,但考虑使用相对布局,比线性布局更强大。 And then place your footer below the list, or better, place your list and your empty view above your footerview.然后将您的页脚放在列表下方,或者更好的是,将您的列表空视图放在您的页脚视图上方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM