Android的ListView的固定页眉和页脚 [英] Android ListView with fixed header and footer

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

问题描述

我怎样才能创建一个的ListView 以固定的页眉和页脚?

How can I create a ListView with fixed header and footer?

我不希望页眉/页脚滚动至的ListView 的项目。

I don't want the header/footer to scroll with the items in the ListView.

难道页眉/页脚是浮在的ListView 使页眉/页脚不需要有直底/顶部的背景和<$ C页眉/页脚视图的背景之下$ C>的ListView 项目滚动,但仍显示列表的第一个元素?

Is it possible that the header/footer is floating over the ListView so that the header/footer dont need to have a straight bottom/top background and the ListView items scrolls below the background of the header/footer view, but still show the first element of the list?

推荐答案

我用@blackbelt建议和一个小的ImageView与源图像是TRANSPARANT与瓷砖的背景就解决了。

I solved it by using @blackbelt suggestion and a small ImageView with the source image being transparant with a tile background.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >

<ListView
android:id="@+id/lv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
  android:layout_above="@+id/tv_footer"
android:layout_below="@+id/tv_header" />

<TextView
android:id="@+id/tv_footer"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/footer_bg"
android:gravity="center"
android:text="Footer" />

<TextView
android:id="@+id/tv_header"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@drawable/header_bg"
android:gravity="center"
android:orientation="vertical"
android:text="Header" />

<ImageView
android:id="@+id/iconView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/lv"
android:background="@drawable/header_bg2"
android:src="@drawable/transparant_bg_tile" />

<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/tv_footer"
android:layout_alignParentRight="true"
android:background="@drawable/footer_bg2"
android:src="@drawable/transparant_bg_tile" />

</RelativeLayout>

从设备屏幕截图

Screenshot from device

这篇关于Android的ListView的固定页眉和页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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