下方固定且始终可见的页脚

下方固定且始终可见的页脚

本文介绍了ListFragment 下方固定且始终可见的页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个固定且始终可见的页脚附加到 ListFragment 的底部.

I'm trying attach a footer, that is fixed and always visible, to the bottom of a ListFragment.

我目前是这样做的:

@Override public void onActivityCreated(Bundle savedInstanceState) {

    // ...

    adapter = new MyAdapter(getActivity(), R.layout.list, dataList);

    ListView list = getListView();
    View footer = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_add, null, false);

    list.addFooterView(footer);
    setListAdapter(adapter);
}

虽然这段代码确实在列表底部生成了一个视图,但它并没有真正做到我想要的:

While this code does produce a view at the bottom of the list, it doesn't really do what I want:

首先,我需要固定页脚,即无论列表滚动到何处,页脚都在屏幕上可见.使用此解决方案,页脚仅在屏幕滚动到列表底部时可见.

First, I need the footer to be FIXED, i.e., visible on the screen regardless of where the list is scrolled. With this solution, the footer is only visible when the screen is scrolled to the bottom of the list.

其次,即使列表为空,我也需要显示页脚.在此解决方案中,当列表为空时,页脚不可见.

Second, I need the footer to appear even when the list is EMPTY. In this solution, the footer is not visible when the list is empty.

让固定页脚(在我的例子中是按钮)始终显示在 ListFragment 或 ListActivity 下方的最佳方法是什么?

What is the best way to get a fixed footer (in my case, a button) to always appear below a ListFragment or ListActivity?

谢谢!

推荐答案

您可以在 xml 布局中做到这一点:

You can do that in the xml layout:

<RelativeLayout>

    <Button android:id="@+id/footer" android:layout_alignParentBottom="true"/>
    <ListView android:id="@android:id/list" android:layout_above="@id/footer"> <!-- the list -->

</RelativeLayout>

此布局将用于片段的 onCreateView 方法中.

This layout will be used in the onCreateView method of the fragment.

这篇关于ListFragment 下方固定且始终可见的页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 03:23