固定和始终可见下方ListFragment页脚 [英] Fixed and always visible footer below ListFragment

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

问题描述

我想附上一个页脚,这是固定的,总是可见,在ListFragment的底部。

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

目前,我正在做这样的:

I'm currently doing it like this:

@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);
}

虽然这code确实产生视图在列表的底部,它并没有真正做我想做的:

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页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆