上一篇中,我们搭建好了一个Demo。没有阅读的可以点击下面的链接:

http://www.cnblogs.com/fuly550871915/p/4866929.html

在这一篇中,我们将实现ListView的底布局。我们首先看实现效果,如下;

即底部出现一个进度条提示正在加载。废话不多说,直接进入代码。

一、底部布局编写

首先把这个底部布局编写出来,名为footer.xml。代码如下:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_horizontal"
>
<LinearLayout
android:id="@+id/load_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleSmall"/><!-- 设置 样式成小的圆形进度条-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="正在加载..."
android:textSize="20sp"/>
</LinearLayout> </LinearLayout>

这样子,底布局文件我们就准备好了。

二、自定义ListView

终于来到这一步了,我们现在要给ListView加上底布局,当然就需要自定义它了。新建类MyListView,继承自ListView。我就不多解释了,代码注释写的很清楚了。如下:

 package com.fuly.load;

 import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView; public class MyListView extends ListView{ //注意,三个构造方法都要重写
public MyListView(Context context) {
super(context);
initView(context); }
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
initView(context);
}
public MyListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initView(context);
} //初始化view
private void initView(Context context){ View footer = LayoutInflater.from(context).inflate(R.layout.footer, null);
//注意,这句代码的意思是给自定义的ListView加上底布局
this.addFooterView(footer); } }

好了,底布局我们可算是加上来了。下面就是使用我们自定义的ListView的时候了。

三、使用带底布局的ListView

这一步是最简单的,就是把之前ListView统统换成我们的MyListView即可。

首先修改activity_main.xml.如下:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ccffff"> <com.fuly.load.MyListView
android:id= "@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="5dp"
android:divider="#00cc00"></com.fuly.load.MyListView>
</LinearLayout>

然后再修改MainActivity里面的即可。改动的地方很少,我还是贴出完成代码吧。如下:

 package com.fuly.load;

 import java.util.ArrayList;
import java.util.List; import android.os.Bundle;
import android.app.Activity; public class MainActivity extends Activity { private MyListView lv;
private List<MyData> mDatas = new ArrayList<MyData>();
private MyAdapter mAdapter; protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); initData();//该方法初始化数据
lv = (MyListView) findViewById(R.id.list_view);
mAdapter = new MyAdapter(this, mDatas);
lv.setAdapter(mAdapter); } /**
* 该方法初始化数据,即提供初始的素材
*/
private void initData() {
for(int i = 0;i<12;i++){
MyData md = new MyData("你好,我是提前设定的");
mDatas.add(md);
} }
}

好了,至此带底布局的ListView我们实现了。赶快运行看看是不是上面的效果吧。下一篇中,我们将实现真正的加载数据。

ListView实现分页加载(二)实现底布局的更多相关文章

  1. ListView实现分页加载(一)制作Demo

    一.什么是分页加载 在下面的文章中,我们来讲解LitView分页加载的实现.什么是分页加载呢?我们先看几张效果图吧,如下:                                       ...

  2. Android基本控件之listView(三)<用ListView实现分页加载>

    我们之前讨论了ListView的基本使用方法和ListView的优化 今天我们再来讨论一个关于ListView的一个新的东西~就是分页加载.那么什么是分页加载呢?简单点说,就是"下拉刷新&q ...

  3. ListView实现分页加载(三)实现分页加载

    在上一篇中,我们实现了底部布局(即带上了进度条).没有读过的朋友可以点击下面的链接: http://www.cnblogs.com/fuly550871915/p/4866966.html 但是进度条 ...

  4. ListView下拉加载二(分页)

    这次在一的基础上做了数据通过HttpClient远程获取显示 并且分页,首先看下效果吧: 以上就是效果图了 下面看下具体代码实现吧 主要代码和上节差不多 主入口代码: package com.tp.s ...

  5. android UI进阶之实现listview的分页加载

    上篇博文和大家分享了下拉刷新,这是一个用户体验非常好的操作方式.新浪微薄就是使用这种方式的典型. 还有个问题,当用户从网络上读取微薄的时候,如果一 下子全部加载用户未读的微薄这将耗费比较长的时间,造成 ...

  6. Android中Listview实现分页加载效果OnScrollListener

    activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android& ...

  7. WinForm ListView不分页加载大量数据

    WinForm的ListView在加载大量数据时会出现闪烁的问题,同时数据加载很慢.如果你的列表中有超过千条的数据且不做特殊处理还是用普通的ListView.Items.Add(),估计你的用户得抱怨 ...

  8. Android ListView分页加载时图片显示问题

    场景:Android ListView需要分页加载,每个item中会有图片,图片又是从网络下载的. 问题:在滑动加载下一页时,上一页的图片明明已经下载完成了,但是无法显示出来. Bug重现: 1,加载 ...

  9. Android中ListView分页加载数据

    public class MainActivity extends Activity { private ListView listView=null; //listview的数据填充器 privat ...

随机推荐

  1. GridView 基本使用

    项目中实例一 <asp:GridView ID="gvBatchReceive" runat="server" AutoGenerateColumns=& ...

  2. Firebird Connection pool is full

    今天在做Firebird V3.0.3  x64 版本内存测试,本地PC上,准备开启800个事务(保持不关闭),每个事务做些事,尽量不释放内存. 每次测试当事务数达到时,就提示Connection p ...

  3. net core 发布到服务器的方式

    ---恢复内容开始(15:05:15)--- using (var scope = ServiceProvider.CreateScope()){ var aSubscriber = Activato ...

  4. HTML <a>标签的使用

    <a></a>标签称作链接标记,由<a>与</a>所围的文字.图片等可以作为一个链接 Eg:<a href="index.html&qu ...

  5. 1.文本编辑器-->CKEditor+CKFinder使用与配置

    一.CKEditor介绍 官网地址:http://ckeditor.com CKEditor下载地址:http://ckeditor.com/download CKFinder(免费版本)下载地址:h ...

  6. 【转】.net MVC 生命周期

    对于Asp.net MVC,我对它的生命周期还是兴趣很浓,于是提出两个问题: 一个HTTP请求从IIS移交到Asp.net运行时,Asp.net MVC是在什么时机获得了控制权并对请求进行处理呢?处理 ...

  7. MySql数据快速导入

    使用LOAD DATA INFILE 插入速度可以提升很多 左侧是直接导入100W花费135s ,Dos界面通过Load方式导入450W只用时23s,性能一下子显示出来了.

  8. 无限滚动条的css布局理解

    一.需求描述 做一个waymo的滚动条,在页面中显示两张图,一共4张图,无限滚动播放. .car{ width: 600px; height: 157px; margin: 100px auto; b ...

  9. js-原始类型和声明变量

    ** Java的基本数据类型:byte.short.int.long.float.double.char.boolean ** 定义变量 都是用关键字 var(ES6中可以使用const和let来定义 ...

  10. 关于display:inline-block布局导致错位问题分析

    移动端设计稿需求是这样的,如下图: 未知的几个头像从左至右并行居中排列. 一般可能直接使用float,但是设计图要求头像排列始终是居中的,于是想到要让它们成为行内元素,然后可使用的方法有flex bo ...