导包
ptr支持ListView ExpandableListView GridView WebView
PullToRefresh是一个古老的下拉刷新框架,以至于并不能在androidstudio中使用gradle引包.
https:
在上述网址中将lib包下载
在androidstudio中import module 将ptr类库import 引来
在setting的project struct 中添加module 即可
使用方法,以listview为例
<com .handmark .pulltorefresh .library .PullToRefreshListView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/pulls_refresh_list_ClassDiaryMainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:cacheColorHint="#00000000"
android:divider="@null"
android:dividerHeight="10dp"
android:scrollbars="none"
//开始上拉和下拉刷新
ptr:ptrMode="both" >
</com .handmark .pulltorefresh .library .PullToRefreshListView >
listview = (PullToRefreshListView) findViewById(R.id.pulls_refresh_list_ClassDiaryMainActivity);
private void configPulltoRefreshListView () {
ILoadingLayout startLoading = listview.getLoadingLayoutProxy(
true , false );
startLoading.setPullLabel("下拉刷新" );
startLoading.setRefreshingLabel("正在刷新中..." );
startLoading.setReleaseLabel("释放即可刷新" );
ILoadingLayout endLoading =listview.getLoadingLayoutProxy(false ,
true );
endLoading.setPullLabel("上拉加载更多" );
endLoading.setRefreshingLabel("拼命加载中..." );
endLoading.setReleaseLabel("释放即可加载更多" );
listview.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ListView>() {
@Override
public void onRefresh (PullToRefreshBase<ListView> refreshView) {
}
});
listview.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
@Override
public void onPullDownToRefresh (PullToRefreshBase<ListView> refreshView) {
listview.onRefreshComplete();
}
@Override
public void onPullUpToRefresh (PullToRefreshBase<ListView> refreshView) {
}
});
}
更多方法
// set mode to BOTH
mExpandList.setMode (Mode.BOTH )
mExpandList.getLoadingLayoutProxy (false, true).setPullLabel (getString(R.string .pull _to_load))
mExpandList.getLoadingLayoutProxy (false, true).setRefreshingLabel (getString(R.string .loading ))
mExpandList.getLoadingLayoutProxy (false, true).setReleaseLabel (getString(R.string .release _to_load))
mExpandList = (PullToRefreshExpandableListView) rootView.findViewById (R.id .expand _list)
mExpandList.getRefreshableView ().setGroupIndicator (null)
mExpandList.getRefreshableView ().setDivider (null)
mExpandList.getRefreshableView ().setSelector (android.R .color .transparent )
mExpandList.getRefreshableView ().setOnGroupClickListener (this)
mExpandList.setOnRefreshListener (this)