如何使最后一个页脚固定(ListView)

Posted

技术标签:

【中文标题】如何使最后一个页脚固定(ListView)【英文标题】:How to make the last footer fixed (ListView) 【发布时间】:2016-06-20 16:15:55 【问题描述】:

我有一个ListView,有 2 个页脚视图。第一个是一堆TextViews,而第二个是一个按钮。我正在尝试修复第二个页脚,使其始终显示在屏幕底部。

我尝试了以下方法:

1.  alignParentBottom = true

2.  layout_gravity="bottom"

3.  footerView2.bringToFront()

以及以上的组合。但他们都没有成功。我怎样才能做到这一点?

更新

我不应该将我一直希望在屏幕上(固定)的View 添加为页脚。

我刚刚在 listView 中添加了想要的固定视图。做了alignParentBottom = trueview.bringToFront()。它对我有用。

【问题讨论】:

当整个列表视图滚动时,第二个页脚将可见并固定,对吧? 是的,当整个列表视图滚动时,第一个页脚会滚动...第二个页脚将始终可见并固定在底部。 在列表视图中添加layout_weight="1" 如果您希望页脚具有永久、固定的位置,请不要使用它。在您的 ListView 下方添加另一个 View 作为布局文件的一部分。 @user5038993 即将与 PPasrtisan 一样。 【参考方案1】:

ListView 和底部页脚分开。这个想法是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_
    android:layout_>

    <Button
        android:id="@+id/btn_bottom"
        android:layout_
        android:layout_
        android:layout_alignParentBottom="true"
        android:text="Bottom button"/>

    <ListView
        android:layout_
        android:layout_
        android:layout_above="@id/btn_bottom"/>

</RelativeLayout>

【讨论】:

是的,这就是我所缺少的。明确点。我还必须使用bringToFront【参考方案2】:

创建单独的 xml 文件,其中包含您想要作为页脚部分的所有文本视图和按钮。然后将此 xml 绑定为列表视图的页脚。您可以通过此方法使用 listview 合并页脚:listview.addFooterView(footerView); 例如:

View footerView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
                .inflate(R.layout.listviewfooter, null, false);
        spDate = (Spinner) headerView.findViewById(R.id.spdate);
        llDatepicker = (LinearLayout) headerView.findViewById(R.id.lldatepicker);
        rvDatepicker = (RecyclerView) headerView.findViewById(R.id.rvdatepicker);
        rvTimepicker = (RecyclerView) headerView.findViewById(R.id.rvtimepicker);

              lvAddress.addFooterView(footerView);

【讨论】:

【参考方案3】:
If you are Trying to add a View which will be shown even if we scroll the List Up or Down... u can do something like this. I had done this before But as a header.

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:id="@+id/new_container"
    android:background="@color/white"
    android:layout_
    android:layout_>

    <Button
        android:layout_
        android:layout_
        android:text="LOAD EARLIER MESSAGES"
        android:id="@+id/loadMore"
        android:background="#90F58220"
        android:visibility="visible"/>

    <RelativeLayout
        android:layout_
        android:layout_
        android:id="@+id/listContainer"
        android:layout_below="@+id/loadMore"
        android:layout_above="@+id/container">
        <ListView
            android:id="@+id/messagesContainer"
            android:transcriptMode="normal"
            android:dividerHeight="0dp"
            android:divider="@null"
            android:stackFromBottom="true"
            android:layout_
            android:layout_ />

       </RelativeLayout>
<RelativeLayout
        android:id="@+id/container"
        android:layout_alignParentBottom="true"
        android:layout_
        android:background="#ffffff"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:paddingLeft="0dp"
        android:paddingRight="0dp"
        android:layout_ >
    </RelativeLayout>

The LoadMore Button is always visible on the Top of the List...
To add it to footer, Just Change

    android:layout_below="@+id/loadMore"
    android:layout_above="@+id/container"

to

    android:layout_above="@+id/loadMore"

【讨论】:

以上是关于如何使最后一个页脚固定(ListView)的主要内容,如果未能解决你的问题,请参考以下文章

如何使页眉和页脚始终固定?

在调整大小时,如何使位置固定页脚不覆盖浏览器的所有其他元素?

更新 ListView 页脚

在页脚之前使固定位置 Div 停止

打印excel表格,怎么设置使每页都有表头和表尾

QML:使用 ListView.OverlayFooter 时页脚中的按钮无响应