Listview - 屏幕底部的页脚 [英] Listview - Footer at the bottom of screen

查看:48
本文介绍了Listview - 屏幕底部的页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有页脚的 ListView,添加了 listview.addFooterView(footerView);

I have a ListView with a footer added with listview.addFooterView(footerView);

除一种情况外,所有工作都按预期进行:当我的列表视图的项目没有填满整个屏幕时,我希望页脚位于屏幕底部,而不是在中间.有没有办法轻松做到这一点?或者我应该改变我的布局?

All works as expected excepted in one case: when my listview's items doesn't fill the whole screen, I would like the footer to be at the bottom of the screen, instead of being in the middle. Is there a way to do this easily? Or should I change my layout?

谢谢

这可能会有所帮助(这就是我想要的)

that might help (this is what I want)

推荐答案

如果你想让它永远在屏幕底部,不管你的 ListView 有多长,那就去掉listview.addFooterView(footerView); 并使用 RelativeLayout.给你的ListView` 属性

If you want it to always be at the bottom of the screen, no matter how long your ListView is, then get rid of listview.addFooterView(footerView); and use a RelativeLayout. Give yourListView` the property

 android:layout_alignParentTop="true"

并将属性赋予您的页脚

 android:layout_alignParentBottom="true"

如果这不能解决您的问题,那么请更具体地说明您想要什么,并尽可能提供您想要什么的图片.

If this doesn't solve your problem then please be a little more specific about what you want and provide a picture of what you want if possible.

编辑

阅读评论后,这可能会奏效.可能有更简单的方法,但您可以执行类似

After reading the comments this might work. There might be an easier way but you could do something like

     listView.post(new Runnable()
     {       
         public void run()
        {
            int numItemsVisible = listView.getLastVisiblePosition() - 
            listView.getFirstVisiblePosition();
            if (itemsAdapter.getCount() - 1 > numItemsVisible)
            {   
                 // set your footer on the ListView
            }
            else
            {
                 footerView.setVisibility(View.VISIBLE);
            }
         }

footerView 将是一个自定义的 layout,您将使用我上面引用的属性创建它.如果项目不超过屏幕大小,则应将其设置为 visible.如果它们无法容纳,那么您可以像现在一样在 ListView 上应用页脚视图.这可能不是最好的方法,但它首先想到的是.您将在设置 Adapter 之前运行此代码.

footerView would be a custom layout that you would create with the properties I referenced above. This should set that to visible if the items aren't more than can fit on the screen. If they are more than can fit then you apply the footer view on the ListView as you are now. This might not be the best way but its the first thing that comes to mind. You would run this code just before you set the Adapter.

这篇关于Listview - 屏幕底部的页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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