下拉刷新上拉加载框架:PtrClassicFrameLayout
1、一个优雅的框架实现下拉刷新上拉加载,学习来源:点击打开链接
2、如何使用:
2.1、在项目中引入:
-
compile 'com.shizhefei:MVCHelper-UltraRefresh:1.3.2'
-
compile 'in.srain.cube:ultra-ptr:1.0.11'
2.2、在布局文件中应用:
<in.srain.cube.views.ptr.PtrClassicFrameLayout
-
xmlns:cube_ptr="http://schemas.android.com/apk/res-auto"
-
android:id="@+id/rotate_header_list_view_frame"
-
android:layout_width="match_parent"
-
android:layout_height="match_parent"
-
cube_ptr:ptr_duration_to_close="200"
-
cube_ptr:ptr_duration_to_close_header="1000"
-
cube_ptr:ptr_keep_header_when_refresh="true"
-
cube_ptr:ptr_pull_to_fresh="false"
-
cube_ptr:ptr_ratio_of_header_height_to_refresh="1.2"
-
cube_ptr:ptr_resistance="1.7" >
-
<ListView
-
android:id="@+id/rotate_header_list_view"
-
android:layout_width="match_parent"
-
android:layout_height="match_parent"
-
android:choiceMode="singleChoice"
-
android:divider="@null"
-
android:fadingEdge="none"
-
android:listSelector="@android:color/transparent"
-
android:paddingLeft="12dp"
-
android:paddingRight="12dp"
-
android:scrollbarStyle="outsideOverlay" />
-
</in.srain.cube.views.ptr.PtrClassicFrameLayout>
2.3、编辑自己的适配器进行数据加载
3、几个主要的方法:
setDataSource:设置数据源,用于加载数据
setAdapter:设置适配器,用于显示数据
setAdapter2:分别设置两种适配器,viewAdapter设置到对应的view上,IDataAdapter 处理显示的逻辑
setOnStateChangeListener:设置状态监听,监听开始刷新,刷新成功,开始加载更多,加载更多成功
refresh:刷新,开启异步线程,并且显示加载中的界面,当数据加载完成自动还原成加载完成的布局,并且刷新列表数
cancel:取消正在执行的取消refresh和loadmore
destory:做销毁操作,比如关闭正在加载数据的异步线程等,一般放在Activity的onDestroy()方法
MOnStateChangeListener:加载监听
isLoading:是否正在加载中