免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2437 | 回复: 0
打印 上一主题 下一主题

Android开发之ListView页眉页脚效果VS android背景渐变 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-03-24 09:57 |只看该作者 |倒序浏览
大家都知道,在我们调用ListView的addFooterView()方法给List增加一个页脚时,如果列表内容很多,超过了屏幕大小,那么页脚就看不到了,可我们一般想要的效果是如下图所示的,在ListView的内容超过屏幕时,页脚还在屏幕的底部。
本文将介绍上图所示的ListView效果,同时介绍一下在android中如何实现渐变效果,就像上图中的页眉页脚的背景色一样。
实现上面的效果主要使用几个RelativeLayout标签和ListView组合即可



[代码] [XML]代码
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.         android:orientation="vertical" android:layout_width="fill_parent"
  4.         android:layout_height="fill_parent">
  5.         <RelativeLayout android:id="@+id/listHeader"
  6.                 android:background="@drawable/jbshape" android:layout_alignParentTop="true"
  7.                 android:gravity="center_horizontal" android:layout_width="fill_parent"
  8.                 android:layout_height="wrap_content">
  9.                 <TextView android:text="IdeasAndroid 列表演示" android:textColor="#000000"
  10.                         android:textSize="18dip" android:layout_width="wrap_content"
  11.                         android:layout_height="wrap_content"></TextView>
  12.         </RelativeLayout>
  13.         <RelativeLayout android:id="@+id/listFooter"
  14.                 android:background="@drawable/jbshape" android:gravity="center_horizontal"
  15.                 android:layout_alignParentBottom="true" android:layout_width="fill_parent"
  16.                 android:layout_height="wrap_content">
  17.                 <Button android:id="@+id/prePage" android:layout_width="wrap_content"
  18.                         android:layout_height="wrap_content" android:text="上一页"
  19.                         android:layout_alignParentLeft="true"></Button>
  20.                 <Button android:layout_width="wrap_content"
  21.                         android:layout_gravity="right" android:layout_height="wrap_content"
  22.                         android:text="下一页" android:layout_toRightOf="@id/prePage"></Button>
  23.         </RelativeLayout>
  24.         <ListView android:id="@+id/myListView" android:layout_width="fill_parent"
  25.                 android:layout_height="fill_parent" android:layout_below="@id/listHeader"
  26.                 android:layout_above="@id/listFooter">
  27.         </ListView>
  28. </RelativeLayout>
复制代码
[代码] 我们在res/drawable目录下新建一个叫jbshape.xml的文件,内容如下所示:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  3.         android:shape="rectangle">
  4.         <gradient android:startColor="#509245" android:centerColor="#3e8532"
  5.                 android:endColor="#509245" android:type="linear" android:angle="90"
  6.                 android:centerX="0.5" android:centerY="0.5" />
  7.         <padding android:left="7dp" android:top="7dp" android:right="7dp"
  8.                 android:bottom="7dp" />
  9.         <corners android:radius="4dp" />
  10. </shape>
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP