【问题标题】:Android ListActivity - how to add a view below the ListView?Android ListActivity - 如何在 ListView 下方添加视图?
【发布时间】:2011-09-05 15:46:30
【问题描述】:

我正在尝试在 ListActivity 的 ListView 下方放置一个 ProgressBar 视图。我希望它始终位于 listView 中的最后一行下方。

只要列表(在运行时由适配器填充)不超过屏幕,就会出现放置在 LinearLayout 中的 ProgressBar。一旦列表大于屏幕,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 不能做到这一点吗?任何帮助表示赞赏。

【问题讨论】:

  • 页脚随列表视图滚动,如果您希望视图固定在屏幕底部,列表视图下方,在列表视图上设置权重

标签: android android-layout android-listview


【解决方案1】:

您应该使用以下方式添加页脚:

list.addFooterView(footerView);

或者手动做,但是考虑使用相对布局,比线性布局更强大。然后将您的页脚放在列表下方,或者更好的是,将您的列表您的空白视图放在您的页脚视图上方。

【讨论】:

  • 谢谢,页脚视图正是我想要的。我现在唯一的小问题是我在我的 ListView 中设置了一个 android:divider,当我将 footerView 设置为 visibility=GONE(它仅在加载更多数据时使用)时,我在底部有两个分隔线。猜猜没有“修复”:-)
猜你喜欢
  • 1970-01-01
  • 2012-04-27
  • 2013-09-20
  • 2015-07-29
  • 2016-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多