如果列表中的项目很少,如何在页面末尾显示页脚视图? [英] how to display footer view to the end of the screen in the case when the list has very few items?

查看:118
本文介绍了如果列表中的项目很少,如何在页面末尾显示页脚视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将页脚添加到列表视图中.当列表项的数量更多时,页脚工作正常. 但是,当listview的项目很少时,页脚将显示在屏幕中间,就在listview的正下方.这看起来很破旧.在这种情况下,我希望页脚与父级底部对齐. 谢谢您.

I want to add a footer to the listview. When the number of list items are more,the footer works fine. But when listview has very few items,the footer gets displayed in the middle of the screen,just below the listview .which looks shabby.In such case i want the footer to align parent bottom. Thankyou in anticipation.

推荐答案

这是您想要的最简单的示例.您可以对其进行自定义:

it is a simplest example of what you want. you can customize it:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

   <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/footer"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >

    </ListView>


    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="90dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:id="@+id/footer" >

    </RelativeLayout>


</RelativeLayout>

如果要按照注释中的说明进行操作,则必须在代码中设置页脚的布局参数,必须获取列表的大小,然后获取屏幕上显示的行数,然后

if you want do that you said in comment you must set layout param's of footer in code, you must get the size of your list, then get the number of row that shows in screen, then

 if (listSize < numRow)
     //set footer to bottom of your list
 else
     //  android:layout_alignParentBottom="true"

这篇关于如果列表中的项目很少,如何在页面末尾显示页脚视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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