github项目https://github.com/woxingxiao/PullToRefreshAndLoadMore
留作自己的笔记
使用:配置
Gradle
dependencies{
compile 'com.xw.repo:PullToRefresh:1.0.1@aar'
}
demo只做了ListView'的刷新加载
对于GridView的刷新加载,需要重写GridView
public class MyGridView extends GridView implements Pullable {
private boolean pullDownEnable = true; //下拉刷新开关
private boolean pullUpEnable = true; //上拉刷新开关
public MyGridView(Context context) {
super(context);
}
public MyGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean canPullDown() {
if (!pullDownEnable)
return false;
if (getCount() == 0) {
// 没有item的时候也可以下拉刷新
return true;
} else if (getFirstVisiblePosition() == 0 && getChildAt(0).getTop() >= 0) {
// 滑到ListView的顶部了
return true;
}
return false;
}
@Override
public boolean canPullUp() {
if (!pullUpEnable)
return false;
if (getCount() == 0) {
// 没有item的时候也可以上拉加载
return true;
} else if (getLastVisiblePosition() == (getCount() - 1)) {
// 滑到底部了
if (getChildAt(getLastVisiblePosition() - getFirstVisiblePosition()) != null
&& getChildAt(getLastVisiblePosition() - getFirstVisiblePosition()).getBottom() <= getMeasuredHeight())
return true;
}
return false;
}
public boolean isPullDownEnable() {
return pullDownEnable;
}
public void setPullDownEnable(boolean pullDownEnable) {
this.pullDownEnable = pullDownEnable;
}
public boolean isPullUpEnable() {
return pullUpEnable;
}
public void setPullUpEnable(boolean pullUpEnable) {
this.pullUpEnable = pullUpEnable;
}
}
其他的刷新加载的控件:
PullToRefreshAndLoad
github:https://github.com/jingchenUSTC/PullToRefreshAndLoad
仅做个人笔记使用