CRefreshLayout
C = Custom(自定義)
CRefreshLayout = 可自定義的下拉刷新框架
源碼下載

<br />
v2.0新增自定義上拉加載框架
<br />
如何導(dǎo)入到項(xiàng)目中:
//在你的project級build.gradle添加
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
//在你的module級build.gradle添加
dependencies {
compile 'com.github.Zhaoss:CRefreshLayout:v2.0'
}
2. 下載源碼后, 將crefreshlayout文件夾作為modle導(dǎo)入進(jìn)來
<br />
如何在項(xiàng)目中使用:
使用方法和SwipeRefreshLayout完全一致(默認(rèn)已實(shí)現(xiàn)一套下拉刷新動畫, 可直接使用)
//在布局文件中
<com.zhaoshuang.crefreshlayout.CRefreshLayout
android:id="@+id/cRefreshLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.zhaoshuang.crefreshlayout.CRefreshLayout>
//在代碼里監(jiān)聽刷新
cRefreshLayout.setOnRefreshListener(new CRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
Toast.makeText(getApplicationContext(), "觸發(fā)刷新", Toast.LENGTH_SHORT).show();
myHandler.sendEmptyMessageDelayed(0, 2000);
}
});
<br />
進(jìn)階使用, 自定義刷新布局
------------------自定義下拉刷新布局-------------------
//傳入自定義view
cRefreshLayout.bindRefreshView(view);
//監(jiān)聽下拉事件
cRefreshLayout.setOnCustomRefreshListener(new CRefreshLayout.OnCustomRefreshListener() {
@Override
public void onStart(View refreshView) {
//開始滑動
}
@Override
public void onMove(View refreshView, int dy, int current, int max) {
//滑動中
}
@Override
public void onUp(View refreshView, int currentY) {
//手指抬起, 此回調(diào)有可能和onRefresh()同時(shí)被調(diào)用
}
@Override
public void onRefresh(View refreshView) {
//觸發(fā)刷新, 此回調(diào)有可能和onUp()同時(shí)被調(diào)用
}
});
------------------自定義上拉加載布局-------------------
//綁定loadView
public void bindLoadView(View loadView)
//設(shè)置上拉加載控件的生命周期監(jiān)聽
cRefreshLayout.setOnCustomLoadListener(new CRefreshLayout.OnCustomLoadListener() {
//開始上拉加載
public void onStart(View loadView)
//上拉拖拽中
//@param dy 本次移動距離
//@param current 已經(jīng)拖拽距離
//@param max 總可拖拽距離
public void onMove(View loadView, int dy, int current, int max)
//手勢抬起
//@param currentY 已經(jīng)拖拽距離
public void onUp(View loadView, int currentY)
//觸發(fā)加載更多
public void onLoad(View loadView)
});
<br />
API
------------------下拉刷新api--------------------
//設(shè)置刷新狀態(tài)
setRefreshing(boolean mRefreshing)
//判斷是否刷新中
ismRefreshing()
//設(shè)置最大拖拽距離
//@param max 值<0 表示不限制拖拽距離
setMaxScroll(int max))
//設(shè)置拖拽速度比, 即下拉拖拽時(shí), 距離移動距離比率
//@param scrollRatio 數(shù)值小于1, 下拉慢, 數(shù)值大于1, 下拉速度快
setMaxScroll(float scrollRatio)
//設(shè)置刷新觸發(fā)點(diǎn), 拖拽距離超過此值, 即滿足刷新條件
//默認(rèn)值為刷新控件的高度
setRefreshY(int refreshY)
//設(shè)置是否響應(yīng)刷新操作
setRefreshState(boolean mRefreshState)
------------------上拉加載api--------------------
//判斷是否加載中
public boolean isLoading()
//設(shè)置上拉加載觸發(fā)點(diǎn), 上拉距離超過此值, 即滿足加載條件
//@param loadY 默認(rèn)值為加載控件的高度
public void setLoadY(int loadY)
//限制上拉加載時(shí)最大拖拽距離
//@param max 值<0 表示不限制拖拽距離
public void setLoadMaxScroll(int max)
//設(shè)置加載狀態(tài)
public void setLoading(boolean loading)
<br />