ListView实现分页加载(二)实现底布局
上一篇中,我们搭建好了一个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实现分页加载(二)实现底布局的更多相关文章
- ListView实现分页加载(一)制作Demo
一.什么是分页加载 在下面的文章中,我们来讲解LitView分页加载的实现.什么是分页加载呢?我们先看几张效果图吧,如下: ...
- Android基本控件之listView(三)<用ListView实现分页加载>
我们之前讨论了ListView的基本使用方法和ListView的优化 今天我们再来讨论一个关于ListView的一个新的东西~就是分页加载.那么什么是分页加载呢?简单点说,就是"下拉刷新&q ...
- ListView实现分页加载(三)实现分页加载
在上一篇中,我们实现了底部布局(即带上了进度条).没有读过的朋友可以点击下面的链接: http://www.cnblogs.com/fuly550871915/p/4866966.html 但是进度条 ...
- ListView下拉加载二(分页)
这次在一的基础上做了数据通过HttpClient远程获取显示 并且分页,首先看下效果吧: 以上就是效果图了 下面看下具体代码实现吧 主要代码和上节差不多 主入口代码: package com.tp.s ...
- android UI进阶之实现listview的分页加载
上篇博文和大家分享了下拉刷新,这是一个用户体验非常好的操作方式.新浪微薄就是使用这种方式的典型. 还有个问题,当用户从网络上读取微薄的时候,如果一 下子全部加载用户未读的微薄这将耗费比较长的时间,造成 ...
- Android中Listview实现分页加载效果OnScrollListener
activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android& ...
- WinForm ListView不分页加载大量数据
WinForm的ListView在加载大量数据时会出现闪烁的问题,同时数据加载很慢.如果你的列表中有超过千条的数据且不做特殊处理还是用普通的ListView.Items.Add(),估计你的用户得抱怨 ...
- Android ListView分页加载时图片显示问题
场景:Android ListView需要分页加载,每个item中会有图片,图片又是从网络下载的. 问题:在滑动加载下一页时,上一页的图片明明已经下载完成了,但是无法显示出来. Bug重现: 1,加载 ...
- Android中ListView分页加载数据
public class MainActivity extends Activity { private ListView listView=null; //listview的数据填充器 privat ...
随机推荐
- js 字符串转dom 和dom 转字符串
js 字符串转dom 和dom 转字符串 博客分类: JavaScript 前言: 在javascript里面动态创建标准dom对象一般使用: var obj = document.createE ...
- jquery.form.js ie 下下载文件已经ie8失效问题解决方案
https://github.com/malsup/form/blob/master/jquery.form.js在使用这个插件时遇到的问题1.ie下会变成下载文件,解决方案是在后端返回时设置'Con ...
- ReSharper+Devexpress 删除光标之后的换行
echo. >"$(ProjectDir)\Properties\licenses.licx" 官方链接
- java 并发 (四) ---- 并发容器
Hashmap 和 Concurrenthashmap Hashmap 不适合并发,应该使用ConcurrentHashMap . 这是很多人都知道的,但是为什么呢? 可以先看一下这两篇文章. JDK ...
- svn在commit后报错:is scheduled for addition, but is missing
今天通过svn 的cr(code review)代码审核后,我欲执行svn ci -m"xxxxxxx(提交注释) ISSUE=3380305",但是没有提交成功,SVN报错啦! ...
- Tidb 离线Ansible方式部署实践
1.最近浏览到一个比较新的分布式数据库Tidb,开源看起来比较牛的样子,一时手痒就动手试试部署 2.参考官方 Ansible 离线方式部署 :https://pingcap.com/docs-cn/o ...
- Python基础学习总结(四)
6.高阶特性 6.1迭代 如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历我们称为迭代(Iteration).在Python中,迭代是通过for ... ...
- jQuery知识点学习整理
零.jQuery中操作css的方法 1.$("p").css("background-color"); 返回首个匹配元素的background-color的值. ...
- WHILE (Transact-SQL)
---循环 declare @n int declare @rowcount int declare @name varchar(50) create table #temp ( id int ide ...
- log在无法调试代码时的妙用
1. 如果修改源代码 通过加入log打印日志 可以判断程序走的流程 找到需要自定义修改的位置(如修改java编写的项目 ApacheDS ) 2. 如果java调用dll文件 出错了 排错的方式也可以 ...