当前位置: 移动技术网 > IT编程>移动开发>Android > Android开发ListView中下拉刷新上拉加载及带列的横向滚动实现方法

Android开发ListView中下拉刷新上拉加载及带列的横向滚动实现方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

flashplayer播放器,中国石化加油卡积分查询,南昌航空大学财务处

listview 控件可使用四种不同视图显示项目。通过此控件,可将项目组成带有或不带有列标头的列,并显示伴随的图标和文本。

可使用 listview 控件将称作 listitem 对象的列表条目组织成下列四种不同的视图之一:1.大(标准)图标2.小图标3.列表4.报表 view 属性决定在列表中控件使用何种视图显示项目。

还可用 labelwrap 属性控制列表中与项目关联的标签是否可换行显示。另外,还可管理列表中项目的排序方法和选定项目的外观。

相信有很人做的项目估计都用的到这个。就是listview的下拉刷新上拉加载还有就是列的横向滚动;

ps:横向滚动带表头与固定列(相信蛮多人都有这样的需求吧?就是在listview上支持很多列,然而设备屏幕宽度有限)

ps:这是我个人在网上找的两个示例demo结合而成的一个示例demo,还可以继续拓展,后续有时间就会更新,大家互相学习

listview下拉刷新上拉加载示例demo原文出处:

listview的横向滚动(带表头与固定列)示例demo原文出处:

接下来就是晒一下项目列表图

java代码

 java代码图

布局文件xml

xml布局

效果图:

横向滚动过的图和下拉刷新,由于不会弄动态图只能这样了

下拉刷新

 下拉刷新

刷新中

 刷新中

上拉加载

上拉加载

接下来就是上代码了,请往下看

这是自定义重写了listview控件autolistview.java

package com.example.testlistview.widget;
import java.text.simpledateformat;
import java.util.date;
import java.util.locale;
import com.example.testlistview.r;
import android.content.context;
import android.util.attributeset;
import android.view.layoutinflater;
import android.view.motionevent;
import android.view.view;
import android.view.viewgroup;
import android.view.animation.linearinterpolator;
import android.view.animation.rotateanimation;
import android.widget.abslistview;
import android.widget.imageview;
import android.widget.progressbar;
import android.widget.textview;
import android.widget.abslistview.onscrolllistener;
import android.widget.listview;
/**
* @author 
* @create
* @version 1.0
* @desc 自定义listview�?下拉刷新,上拉加载更多
*/
public class autolistview extends listview implements onscrolllistener {
// 区分当前操作是刷新还是加�?
public static final int refresh = 0;
public static final int load = 1;
// 区分pull和release的距离的大小
private static final int space = 20;
// 定义header的四种状态和当前状�??
private static final int none = 0;
private static final int pull = 1;
private static final int release = 2;
private static final int refreshing = 3;
private int state;
private layoutinflater inflater;
private view header;
private view footer;
private textview tip;
private textview lastupdate;
private imageview arrow;
private progressbar refreshing;
private textview nodata;
private textview loadfull;
private textview more;
private progressbar loading;
private rotateanimation animation;
private rotateanimation reverseanimation;
private int starty;
private int firstvisibleitem;
private int scrollstate;
private int headercontentinitialheight;
private int headercontentheight;
// 只有在listview第一个item显示的时候(listview滑到了顶部)才进行下拉刷新, 否则此时的下拉只是滑动listview
private boolean isrecorded;
private boolean isloading;// 判断是否正在加载
private boolean loadenable = true;// �?启或者关闭加载更多功�?
private boolean isloadfull;
private int pagesize = 10;
private onrefreshlistener onrefreshlistener;
private onloadlistener onloadlistener;
public autolistview(context context) {
super(context);
initview(context);
}
public autolistview(context context, attributeset attrs) {
super(context, attrs);
initview(context);
}
public autolistview(context context, attributeset attrs, int defstyle) {
super(context, attrs, defstyle);
initview(context);
}
// 下拉刷新监听
public void setonrefreshlistener(onrefreshlistener onrefreshlistener) {
this.onrefreshlistener = onrefreshlistener;
}
// 加载更多监听
public void setonloadlistener(onloadlistener onloadlistener) {
this.loadenable = true;
this.onloadlistener = onloadlistener;
}
public boolean isloadenable() {
return loadenable;
}
// 这里的开启或者关闭加载更多,并不支持动�?�调�?
public void setloadenable(boolean loadenable) {
this.loadenable = loadenable;
this.removefooterview(footer);
}
public int getpagesize() {
return pagesize;
}
public void setpagesize(int pagesize) {
this.pagesize = pagesize;
}
// 初始化组�?
private void initview(context context) {
// 设置箭头特效
animation = new rotateanimation(0, -180, rotateanimation.relative_to_self, 0.5f,
rotateanimation.relative_to_self, 0.5f);
animation.setinterpolator(new linearinterpolator());
animation.setduration(1000);
animation.setfillafter(true);
reverseanimation = new rotateanimation(-180, 0, rotateanimation.relative_to_self, 0.5f,
rotateanimation.relative_to_self, 0.5f);
reverseanimation.setinterpolator(new linearinterpolator());
reverseanimation.setduration(1000);
reverseanimation.setfillafter(true);
inflater = layoutinflater.from(context);
footer = inflater.inflate(r.layout.listview_footer, null);
loadfull = (textview) footer.findviewbyid(r.id.loadfull);
nodata = (textview) footer.findviewbyid(r.id.nodata);
more = (textview) footer.findviewbyid(r.id.more);
loading = (progressbar) footer.findviewbyid(r.id.loading);
header = inflater.inflate(r.layout.pull_to_refresh_header, null);
arrow = (imageview) header.findviewbyid(r.id.arrow);
tip = (textview) header.findviewbyid(r.id.tip);
lastupdate = (textview) header.findviewbyid(r.id.lastupdate);
refreshing = (progressbar) header.findviewbyid(r.id.refreshing);
// 为listview添加头部和尾部,并进行初始化
headercontentinitialheight = header.getpaddingtop();
measureview(header);
headercontentheight = header.getmeasuredheight();
toppadding(-headercontentheight);
this.addheaderview(header);
this.addfooterview(footer);
this.setonscrolllistener(this);
}
public void onrefresh() {
if (onrefreshlistener != null) {
onrefreshlistener.onrefresh();
}
}
public void onload() {
if (onloadlistener != null) {
onloadlistener.onload();
}
}
public void onrefreshcomplete(string updatetime) {
lastupdate.settext(this.getcontext().getstring(r.string.lastupdatetime, getcurrenttime()));
state = none;
refreshheaderviewbystate();
}
// 用于下拉刷新结束后的回调
public void onrefreshcomplete() {
string currenttime = getcurrenttime();
onrefreshcomplete(currenttime);
}
// 用于加载更多结束后的回调
public void onloadcomplete() {
isloading = false;
}
@override
public void onscroll(abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) {
this.firstvisibleitem = firstvisibleitem;
}
@override
public void onscrollstatechanged(abslistview view, int scrollstate) {
this.scrollstate = scrollstate;
ifneedload(view, scrollstate);
}
// 根据listview滑动的状态判断是否需要加载更�?
private void ifneedload(abslistview view, int scrollstate) {
if (!loadenable) {
return;
}
try {
if (scrollstate == onscrolllistener.scroll_state_idle && !isloading
&& view.getlastvisibleposition() == view.getpositionforview(footer) && !isloadfull) {
onload();
isloading = true;
}
} catch (exception e) {
}
}
/**
* 监听触摸事件,解读手�?
*/
@override
public boolean ontouchevent(motionevent ev) {
switch (ev.getaction()) {
// case motionevent.action_down:
// if (firstvisibleitem == 0) {
// isrecorded = true;
// starty = (int) ev.gety();
// }
// break;
case motionevent.action_cancel:
case motionevent.action_up:
if (state == pull) {
state = none;
refreshheaderviewbystate();
} else if (state == release) {
state = refreshing;
refreshheaderviewbystate();
onrefresh();
}
isrecorded = false;
break;
case motionevent.action_move:
whenmove(ev);
break;
}
return super.ontouchevent(ev);
}
@override
public boolean onintercepttouchevent(motionevent ev) {
if (ev.getaction() == motionevent.action_down) {
if (firstvisibleitem == 0) {
isrecorded = true;
starty = (int) ev.gety();
}
}
return super.onintercepttouchevent(ev);
}
// 解读手势,刷新header状�??
private void whenmove(motionevent ev) {
if (!isrecorded) {
return;
}
int tmpy = (int) ev.gety();
int space = tmpy - starty;
int toppadding = space - headercontentheight;
switch (state) {
case none:
if (space > 0) {
state = pull;
refreshheaderviewbystate();
}
break;
case pull:
toppadding(toppadding);
if (scrollstate == scroll_state_touch_scroll && space > headercontentheight + space) {
state = release;
refreshheaderviewbystate();
}
break;
case release:
toppadding(toppadding);
if (space > 0 && space < headercontentheight + space) {
state = pull;
refreshheaderviewbystate();
} else if (space <= 0) {
state = none;
refreshheaderviewbystate();
}
break;
}
}
// 调整header的大小�?�其实调整的只是距离顶部的高度�??
private void toppadding(int toppadding) {
header.setpadding(header.getpaddingleft(), toppadding, header.getpaddingright(), header.getpaddingbottom());
header.invalidate();
}
/**
* 这个方法是根据结果的大小来决定footer显示的�??
* <p>
* 这里假定每次请求的条数为10。如果请求到�?10条�?�则认为还有数据。如过结果不�?10条,则认为数据已经全部加载,
* 这时footer显示已经全部加载
* </p>
* 
* @param resultsize
*/
public void setresultsize(int resultsize) {
if (resultsize == 0) {
isloadfull = true;
loadfull.setvisibility(view.gone);
loading.setvisibility(view.gone);
more.setvisibility(view.gone);
nodata.setvisibility(view.visible);
} else if (resultsize > 0 && resultsize < pagesize) {
isloadfull = true;
loadfull.setvisibility(view.visible);
loading.setvisibility(view.gone);
more.setvisibility(view.gone);
nodata.setvisibility(view.gone);
} else if (resultsize == pagesize) {
isloadfull = false;
loadfull.setvisibility(view.gone);
loading.setvisibility(view.visible);
more.setvisibility(view.visible);
nodata.setvisibility(view.gone);
}
}
// 根据当前状�?�,调整header
private void refreshheaderviewbystate() {
switch (state) {
case none:
toppadding(-headercontentheight);
tip.settext(r.string.pull_to_refresh);
refreshing.setvisibility(view.gone);
arrow.clearanimation();
arrow.setimageresource(r.drawable.pull_to_refresh_arrow);
break;
case pull:
arrow.setvisibility(view.visible);
tip.setvisibility(view.visible);
lastupdate.setvisibility(view.visible);
refreshing.setvisibility(view.gone);
tip.settext(r.string.pull_to_refresh);
arrow.clearanimation();
arrow.setanimation(reverseanimation);
break;
case release:
arrow.setvisibility(view.visible);
tip.setvisibility(view.visible);
lastupdate.setvisibility(view.visible);
refreshing.setvisibility(view.gone);
tip.settext(r.string.pull_to_refresh);
tip.settext(r.string.release_to_refresh);
arrow.clearanimation();
arrow.setanimation(animation);
break;
case refreshing:
toppadding(headercontentinitialheight);
refreshing.setvisibility(view.visible);
arrow.clearanimation();
arrow.setvisibility(view.gone);
tip.setvisibility(view.gone);
lastupdate.setvisibility(view.gone);
break;
}
}
// 用来计算header大小的�?�比较隐晦�?�因为header的初始高度就�?0,貌似可以不用�?
private void measureview(view child) {
viewgroup.layoutparams p = child.getlayoutparams();
if (p == null) {
p = new viewgroup.layoutparams(viewgroup.layoutparams.match_parent, viewgroup.layoutparams.wrap_content);
}
int childwidthspec = viewgroup.getchildmeasurespec(0, 0 + 0, p.width);
int lpheight = p.height;
int childheightspec;
if (lpheight > 0) {
childheightspec = measurespec.makemeasurespec(lpheight, measurespec.exactly);
} else {
childheightspec = measurespec.makemeasurespec(0, measurespec.unspecified);
}
child.measure(childwidthspec, childheightspec);
}
/*
* 定义下拉刷新接口
*/
public interface onrefreshlistener {
public void onrefresh();
}
/*
* 定义加载更多接口
*/
public interface onloadlistener {
public void onload();
}
public string getcurrenttime(string format) {
date date = new date();
simpledateformat sdf = new simpledateformat(format, locale.getdefault());
string currenttime = sdf.format(date);
return currenttime;
}
public string getcurrenttime() {
return getcurrenttime("yyyy-mm-dd hh:mm:ss");
}
}

这是自定义horizontalscrollview的重写 chscrollview.java

package com.example.testlistview.widget;
import java.util.arraylist;
import java.util.list;
import com.example.testlistview.widget.chscrollview.chscrollviewhelper;
import android.content.context;
import android.util.attributeset;
import android.util.log;
import android.view.motionevent;
import android.widget.horizontalscrollview;
import android.widget.toast;
public class chscrollview extends horizontalscrollview {
private context context;
float startx = 0;
float offset;
public chscrollview(context context, attributeset attrs, int defstyle) {
super(context, attrs, defstyle);
this.context = context;
}
public chscrollview(context context, attributeset attrs) {
super(context, attrs);
this.context = context;
}
public chscrollview(context context) {
super(context);
this.context = context;
}
@override
public boolean ontouchevent(motionevent ev) {
// 进行触摸赋值
chscrollviewhelper.mtouchview = this;
return super.ontouchevent(ev);
}
@override
protected void onscrollchanged(int l, int t, int oldl, int oldt) {
// 当当前的chscrollview被触摸时,滑动其它
if (chscrollviewhelper.mtouchview == this) {
onscrollchanged(l, t, oldl, oldt, 0);
} else {
super.onscrollchanged(l, t, oldl, oldt);
}
}
public void onscrollchanged(int l, int t, int oldl, int oldt, int none) {
for (chscrollview scrollview : chscrollviewhelper.mhscrollviews) {
// 防止重复滑动
if (chscrollviewhelper.mtouchview != scrollview)
scrollview.smoothscrollto(l, t);
}
}
public static class chscrollviewhelper {
public static horizontalscrollview mtouchview;
public static list<chscrollview> mhscrollviews = new arraylist<chscrollview>();
public static void addhviews(final chscrollview hscrollview, autolistview autolistview) {
if (!chscrollviewhelper.mhscrollviews.isempty()) {
int size = chscrollviewhelper.mhscrollviews.size();
chscrollview scrollview = chscrollviewhelper.mhscrollviews.get(size - 1);
final int scrollx = scrollview.getscrollx();
// 第一次满屏后,向下滑动,有一条数据在开始时未加入
if (scrollx != 0) {
autolistview.post(new runnable() {
@override
public void run() {
// 当listview刷新完成之后,把该条移动到最终位置
hscrollview.scrollto(scrollx, 0);
}
});
}
}
chscrollviewhelper.mhscrollviews.add(hscrollview);
}
}
}

这是listview的适配器adapter ,listviewscrolladapter.java

package com.example.testlistview.adapter;
import java.util.list;
import java.util.map;
import com.example.testlistview.r;
import com.example.testlistview.widget.autolistview;
import com.example.testlistview.widget.chscrollview;
import com.example.testlistview.widget.chscrollview.chscrollviewhelper;
import android.content.context;
import android.view.layoutinflater;
import android.view.view;
import android.view.viewgroup;
import android.widget.simpleadapter;
import android.widget.textview;
public class listviewscrolladapter extends simpleadapter {
private list<? extends map<string, ?>> datas;
private int res;
private string[] from;
private int[] to;
private context context;
private int resscroll;
private autolistview lstv;
public listviewscrolladapter(context context, list<? extends map<string, ?>> data, int resource, string[] from,
int[] to, int resourceitem,autolistview autolistview) {
super(context, data, resource, from, to);
this.context = context;
this.datas = data;
this.res = resource;
this.from = from;
this.to = to;
this.resscroll = resourceitem;
this.lstv = autolistview;
}
@override
public int getcount() {
return this.datas.size();
}
@override
public view getview(int position, view convertview, viewgroup parent) {
view v = convertview;
if (v == null) {
v = layoutinflater.from(context).inflate(res, null);
// 第一次初始化的时候装进来
chscrollviewhelper.addhviews((chscrollview) v.findviewbyid(resscroll), lstv);
view[] views = new view[to.length];
for (int i = 0; i < to.length; i++) {
view tv = v.findviewbyid(to[i]);
views[i] = tv;
}
v.settag(views);
}
v.setbackgroundresource(r.drawable.selector_bg_white_gray);
view[] holders = (view[]) v.gettag();
int len = holders.length;
for (int i = 0; i < len; i++) {
((textview) holders[i]).settext(this.datas.get(position).get(from[i]).tostring());
}
return v;
}
public context getcontext() {
return context;
}
}

这是mainactivity.java

package com.example.testlistview;
import android.os.bundle;
import android.os.handler;
import android.os.message;
import android.view.view;
import android.widget.adapterview.onitemclicklistener;
import android.widget.adapterview;
import android.widget.textview;
import android.widget.toast;
import java.util.arraylist;
import java.util.hashmap;
import java.util.list;
import java.util.map;
import com.example.testlistview.widget.autolistview.onloadlistener;
import com.example.testlistview.widget.autolistview.onrefreshlistener;
import com.example.testlistview.r;
import com.example.testlistview.adapter.listviewscrolladapter;
import com.example.testlistview.widget.autolistview;
import com.example.testlistview.widget.chscrollview;
import com.example.testlistview.widget.chscrollview.chscrollviewhelper;
import android.annotation.suppresslint;
import android.app.activity;
public class mainactivity extends activity implements onrefreshlistener, onloadlistener, onitemclicklistener {
private autolistview lstv;
private chscrollview headerscroll;
list<map<string, string>> list = new arraylist<map<string, string>>();
private listviewscrolladapter adapter;
@suppresslint("handlerleak")
private handler handler = new handler() {
@suppresswarnings("unchecked")
public void handlemessage(message msg) {
list<map<string, string>> result = (list<map<string, string>>) msg.obj;
switch (msg.what) {
case autolistview.refresh:
lstv.onrefreshcomplete();
list.clear();
list.addall(result);
break;
case autolistview.load:
lstv.onloadcomplete();
list.addall(result);
break;
}
lstv.setresultsize(result.size());
adapter.notifydatasetchanged();
};
};
@override
protected void oncreate(bundle savedinstancestate) {
super.oncreate(savedinstancestate);
setcontentview(r.layout.activity_main);
initview();
initdata();
}
private void initview() {
headerscroll = (chscrollview) findviewbyid(r.id.item_scroll_title);
chscrollviewhelper.mhscrollviews.clear();
// 添加头滑动事件
chscrollviewhelper.mhscrollviews.add(headerscroll);
lstv = (autolistview) findviewbyid(r.id.scroll_list);
adapter = new listviewscrolladapter(this, list, r.layout.auto_listview_item,
new string[] { "title", "data_1", "data_2", "data_3", "data_4", "data_5", "data_6", },
new int[] { r.id.item_title, r.id.item_data1, r.id.item_data2, r.id.item_data3, r.id.item_data4,
r.id.item_data5, r.id.item_data6 },
r.id.item_scroll, lstv);
lstv.setadapter(adapter);
lstv.setonrefreshlistener(this);
lstv.setonloadlistener(this);
lstv.setonitemclicklistener(this);
}
private void initdata() {
loaddata(autolistview.refresh);
}
private void loaddata(final int what) {
// 这里模拟从服务器获取数据
new thread(new runnable() {
@override
public void run() {
try {
thread.sleep(700);
} catch (interruptedexception e) {
e.printstacktrace();
}
message msg = handler.obtainmessage();
msg.what = what;
msg.obj = getdata();
handler.sendmessage(msg);
}
}).start();
}
@override
public void onrefresh() {
loaddata(autolistview.refresh);
}
@override
public void onload() {
loaddata(autolistview.load);
}
@override
public void onitemclick(adapterview<?> arg0, view arg1, int arg2, long arg3) {
try {
textview textview = (textview) arg1.findviewbyid(r.id.item_data2);
toast.maketext(this, "你点击了:" + textview.gettext(), toast.length_short).show();
} catch (exception ex) {
}
}
// 测试数据
public list<map<string, string>> getdata() {
list<map<string, string>> result = new arraylist<map<string, string>>();
map<string, string> data = null;
for (int i = 0; i < 10; i++) {
data = new hashmap<string, string>();
data.put("title", "title_" + i);
data.put("data_" + 1, "date_" + 1 + "_" + i);
data.put("data_" + 2, "date_" + 2 + "_" + i);
data.put("data_" + 3, "date_" + 3 + "_" + i);
data.put("data_" + 4, "date_" + 4 + "_" + i);
data.put("data_" + 5, "date_" + 5 + "_" + i);
data.put("data_" + 6, "date_" + 6 + "_" + i);
result.add(data);
}
return result;
}
}

这是layout布局文件 activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<linearlayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ccc"
android:minheight="40dip"
android:orientation="horizontal" >
<textview
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:gravity="center"
android:text="表头测试"
android:textcolor="#850" />
<com.example.testlistview.widget.chscrollview
android:id="@+id/item_scroll_title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:scrollbars="none" >
<linearlayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<textview
android:layout_width="100dip"
android:layout_height="fill_parent"
android:gravity="center"
android:text="date1"
android:textcolor="#850" />
<textview
android:layout_width="100dip"
android:layout_height="fill_parent"
android:gravity="center"
android:text="date2"
android:textcolor="#850" />
<textview
android:layout_width="100dip"
android:layout_height="fill_parent"
android:gravity="center"
android:text="date3"
android:textcolor="#850" />
<textview
android:layout_width="100dip"
android:layout_height="fill_parent"
android:gravity="center"
android:text="date4"
android:textcolor="#850" />
<textview
android:layout_width="100dip"
android:layout_height="fill_parent"
android:gravity="center"
android:text="date5"
android:textcolor="#850" />
<textview
android:layout_width="100dip"
android:layout_height="fill_parent"
android:gravity="center"
android:text="date6"
android:textcolor="#850" />
</linearlayout>
</com.example.testlistview.widget.chscrollview>
</linearlayout>
<com.example.testlistview.widget.autolistview
android:id="@+id/scroll_list"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:cachecolorhint="@android:color/transparent" />
</linearlayout>

auto_listview_item.xml布局文件 listview的item布局文件

<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantfocusability="blocksdescendants"
android:minheight="50dip"
android:orientation="horizontal" >
<textview
android:id="@+id/item_title"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center"
android:text="表头测试" />
<com.example.testlistview.widget.chscrollview
android:id="@+id/item_scroll"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:focusable="false"
android:scrollbars="none" >
<linearlayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<textview
android:id="@+id/item_data1"
android:layout_width="100dip"
android:layout_height="fill_parent"
android:gravity="center"
android:textcolor="#011" />
<textview
android:id="@+id/item_data2"
android:layout_width="100dip"
android:layout_height="fill_parent"
android:gravity="center"
android:textcolor="#191" />
<textview
android:id="@+id/item_data3"
android:layout_width="100dip"
android:layout_height="fill_parent"
android:gravity="center"
android:textcolor="#101" />
<textview
android:id="@+id/item_data4"
android:layout_width="100dip"
android:layout_height="fill_parent"
android:gravity="center"
android:textcolor="#111" />
<textview
android:id="@+id/item_data5"
android:layout_width="100dip"
android:layout_height="fill_parent"
android:gravity="center"
android:textcolor="#071" />
<textview
android:id="@+id/item_data6"
android:layout_width="100dip"
android:layout_height="fill_parent"
android:gravity="center"
android:textcolor="#910" />
</linearlayout>
</com.example.testlistview.widget.chscrollview>
</linearlayout>

listview底部提示正在加载中的布局文件 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="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<textview
android:id="@+id/loadfull"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:text="@string/load_full"
android:visibility="gone" />
<textview
android:id="@+id/nodata"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:text="@string/no_data"
android:visibility="gone" />
<textview
android:id="@+id/more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:text="@string/more" />
<progressbar
android:id="@+id/loading"
style="@style/customprogressbar" />
</linearlayout>

listview顶部提示下拉刷新的一些状态布局xml文件 pull_to_refresh_header.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:gravity="center"
android:orientation="vertical" >
<relativelayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingbottom="5dp" >
<linearlayout
android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerhorizontal="true"
android:layout_centervertical="true"
android:orientation="vertical" >
<progressbar
android:id="@+id/refreshing"
style="@style/customprogressbar" />
<textview
android:id="@+id/tip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<textview
android:id="@+id/lastupdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textsize="12sp" />
</linearlayout>
<imageview
android:id="@+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centervertical="true"
android:layout_marginright="20dp"
android:layout_toleftof="@id/layout"
android:contentdescription="@string/d"
android:src="@drawable/pull_to_refresh_arrow" />
</relativelayout>
<imageview
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/h_line"
android:contentdescription="@string/d" />
</linearlayout>
<uses-sdk
android:minsdkversion="8"
android:targetsdkversion="15" />

android编译和目标版本是4.0.3

以上所述是小编给大家介绍的android开发listview中下拉刷新上拉加载及带列的横向滚动实现方法,希望对大家有所帮助

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网