首页 / 操作系统 / Linux / Android开发之ListView页眉页脚效果VS android背景渐变
大家都知道,在我们调用ListView的addFooterView()方法给List增加一个页脚时,如果列表内容很多,超过了屏幕大小,那么页脚就看不到了,可我们一般想要的效果是如下图所示的,在ListView的内容超过屏幕时,页脚还在屏幕的底部。 本文将介绍上图所示的ListView效果,同时介绍一下在Android中如何实现渐变效果,就像上图中的页眉页脚的背景色一样。 实现上面的效果主要使用几个RelativeLayout标签和ListView组合即可,代码如下所示: < ?xml version="1.0" encoding="utf-8"?> < RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> < RelativeLayout android:id="@+id/listHeader" android:background="@drawable/jbshape" android:layout_alignParentTop="true" android:gravity="center_horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> < TextView android:text="IdeasAndroid 列表演示" android:textColor="#000000" android:textSize="18dip" android:layout_width="wrap_content" android:layout_height="wrap_content">< /TextView> < /RelativeLayout> < RelativeLayout android:id="@+id/listFooter" android:background="@drawable/jbshape" android:gravity="center_horizontal" android:layout_alignParentBottom="true" android:layout_width="fill_parent" android:layout_height="wrap_content"> < Button android:id="@+id/prePage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="上一页" android:layout_alignParentLeft="true">< /Button> < Button android:layout_width="wrap_content" android:layout_gravity="right" android:layout_height="wrap_content"android:text="下一页" android:layout_toRightOf="@id/prePage">< /Button> < /RelativeLayout> < ListView android:id="@+id/myListView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@id/listHeader" android:layout_above="@id/listFooter"> < /ListView> < /RelativeLayout>