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 ...
随机推荐
- Cannot find module 'object-keys' 的解决办法
把node_modules文件夹删除,重新cnpm install安装node_modules就好了.
- 快速删除node_modules目录
当node项目需要重新安装依赖,并且需要删除原有的node_modules目录时,windows下删除该目录比较麻烦的,所以我就在网上找了个npm包,名字叫做 rimraf 安装步骤: npm ins ...
- Chetsheet: 2017 01.01 ~ 01.31
Web TypeScript: the missing introduction Async HTTP API and service bus Optimizing the Performance o ...
- 怎么让textarea的光标靠左对齐
1.怎么让textarea的光标靠左对齐: 把<textarea></textarea>之间空隙去掉就可以了. 2.怎么限制textarea的字数,利用maxlength属性限 ...
- v-model的双向数据绑定(表单)
可以用 v-model 指令在表单 <input>.<textarea> 及 <select> 元素上创建双向数据绑定.它会根据控件类型自动选取正确的方法来更新元素 ...
- 各种常用的JSON接口
这里为大家搜集了一些能够返回JSON格式的服务接口.部分需要用JSONP调用. 其中一些接口提供用例参照:http://www.bejson.com/webInterface.php 天气接口 气象局 ...
- java.sql.SQLException: Incorrect string value: '\xF0\x9F\x9A\x80\xF0\x9F...' for column 'name' at row 1
1.异常提示: 12:59:10.000 [http-nio-8080-exec-40] DEBUG o.s.j.s.SQLStateSQLExceptionTranslator - Extracte ...
- 前端面试经典题目合集(HTML+CSS)一
1.说说你对HTML语义化的理解? (1)什么是HTML语义化? 根据内容的结构化(内容语义化),选择合适的标签(代码语义化)便于开发者阅读和写出更优雅的代码的同时让浏览器的爬虫和机器很好地解析. ( ...
- Linux基础之命令练习Day7-nginx,nfs
一. Nginx Nginx("engine x") 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由Igor Sysoev为俄罗 ...
- ArcGIS 编程中对接口的理解
学习AO,最重要的是理解“接口”这个概念.接口是什么?有什么具体作用?在多种计算机高级语言中,都可以看到“接口”这个术语,但基本上每一本书对“为什么使用接口”等重要文都都“语焉不详”,使得初学者往往不 ...