展会信息港展会大全

Android开发 ListView页眉页脚效果VS android背景渐变
来源:互联网   发布日期:2015-11-25 22:46:03   浏览:3109次  

导读:大家都知道,在我们调用ListView的addFooterView()方法给List增加一个页脚时,如果列表内容很多,超过了屏幕大小,那么页脚就看不到了,可我们一般想要的效果是如下图所示的,在ListView的内容超过屏幕时,页脚还......

大家都知道,在我们调用ListView的addFooterView()方法给List增加一个页脚时,如果列表内容很多,超过了屏幕大小,那么页脚就看不到了,可我们一般想要的效果是如下图所示的,在ListView的内容超过屏幕时,页脚还在屏幕的底部。

本文将介绍上图所示的ListView效果,同时介绍一下在android中如何实现渐变效果,就像上图中的页眉页脚的背景色一样。

实现上面的效果主要使用几个RelativeLayout标签和ListView组合即可

[代码] [XML]代码

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayoutxmlns: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>

[代码] 我们在res/drawable目录下新建一个叫jbshape.xml的文件,内容如下所示:

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"

android:shape="rectangle">

<gradient android:startColor="#509245"android:centerColor="#3e8532"

android:endColor="#509245" android:type="linear"android:angle="90"

android:centerX="0.5" android:centerY="0.5" />

<padding android:left="7dp" android:top="7dp" android:right="7dp"

android:bottom="7dp" />

<corners android:radius="4dp" />

</shape>

赞助本站

人工智能实验室

相关热词: 页眉 页脚 背景 渐变

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港