问题描述
如何创建带有固定页眉和页脚的 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
上,以便页眉/页脚不需要具有直下/顶部背景和 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 解决了这个问题,源图像是透明的,带有瓷砖背景.
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>
设备截图
这篇关于带有固定页眉和页脚的 Android ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!