【问题标题】:Setting a footer in a ListView在 ListView 中设置页脚
【发布时间】:2012-01-02 14:03:29
【问题描述】:

我需要在我的应用程序末尾添加一个按钮,而不是覆盖按钮的项目。使用我当前的代码,按钮被 ListView 中的项目覆盖。我希望能够滚动 ListView 并查看所有项目,而按钮不会被它们覆盖。我需要在 Listview 下方带有 ID 为“bSave”的按钮。我的 XML 代码:

按钮

<LinearLayout android:layout_width="match_parent"
    android:layout_height="wrap_content" android:orientation="vertical"
    android:id="@+id/bottom_control_bar"
    android:layout_alignParentBottom="true">

    <Button android:layout_width="match_parent"
        android:layout_height="wrap_content" android:text="Spara total tid"
        android:id="@+id/bSave" android:textStyle="bold"
        android:visibility="invisible"></Button>
</LinearLayout>

列表视图

<RelativeLayout
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ListView android:id="@android:id/list"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_above="@id/bottom_control_bar"></ListView>
    <TextView android:id="@android:id/empty"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" />

</RelativeLayout>

【问题讨论】:

  • 您希望按钮在列表末尾还是在屏幕底部始终可见?

标签: android xml listview footer


【解决方案1】:

您希望按钮始终可见,还是仅在您阅读列表末尾时才可见?如果是前者,那么您可以使用 relativelayout 之类的东西,并将页脚按钮设置为 alignparentbottombelow listview。如果是后者,那么调用listview.addFooterView,传入你想要的任何视图。

【讨论】:

    【解决方案2】:

    尝试使用 ScrollView http://developer.android.com/reference/android/widget/ScrollView.html

    <LinearLayout>
    <ScrollView>
    </ScrollView>
    
    <Button>
    </Button>
    
    </LinearLayout>
    

    【讨论】:

    • 我需要一个列表视图来显示我的项目
    猜你喜欢
    • 2018-05-08
    • 1970-01-01
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    • 2013-08-05
    • 1970-01-01
    相关资源
    最近更新 更多