標籤:

CRefreshLayout 可自定義的下拉刷新框架

CRefreshLayout

C = Custom(自定義)

CRefreshLayout = 可自定義的下拉刷新框架

源碼下載

v2.0新增自定義上拉載入框架

如何導入到項目中:

1. 使用Jitpack方式

//在你的project級build.gradle添加allprojects { repositories { ... maven { url https://jitpack.io } }}//在你的module級build.gradle添加dependencies { compile com.github.Zhaoss:CRefreshLayout:v2.0}

2. 下載源碼後, 將crefreshlayout文件夾作為modle導入進來

如何在項目中使用:

使用方法和SwipeRefreshLayout完全一致(默認已實現一套下拉刷新動畫, 可直接使用)

//在布局文件中<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>//在代碼里監聽刷新cRefreshLayout.setOnRefreshListener(new CRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { Toast.makeText(getApplicationContext(), "觸發刷新", Toast.LENGTH_SHORT).show(); myHandler.sendEmptyMessageDelayed(0, 2000); }});

進階使用, 自定義刷新布局

------------------自定義下拉刷新布局-------------------//傳入自定義viewcRefreshLayout.bindRefreshView(view);//監聽下拉事件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) { //手指抬起, 此回調有可能和onRefresh()同時被調用 } @Override public void onRefresh(View refreshView) { //觸發刷新, 此回調有可能和onUp()同時被調用 }});------------------自定義上拉載入布局-------------------//綁定loadViewpublic void bindLoadView(View loadView)//設置上拉載入控制項的生命周期監聽cRefreshLayout.setOnCustomLoadListener(new CRefreshLayout.OnCustomLoadListener() { //開始上拉載入 public void onStart(View loadView) //上拉拖拽中 //@param dy 本次移動距離 //@param current 已經拖拽距離 //@param max 總可拖拽距離 public void onMove(View loadView, int dy, int current, int max) //手勢抬起 //@param currentY 已經拖拽距離 public void onUp(View loadView, int currentY) //觸發載入更多 public void onLoad(View loadView)});

API

------------------下拉刷新api--------------------//設置刷新狀態setRefreshing(boolean mRefreshing)//判斷是否刷新中ismRefreshing()//設置最大拖拽距離//@param max 值<0 表示不限制拖拽距離setMaxScroll(int max))//設置拖拽速度比, 即下拉拖拽時, 距離移動距離比率//@param scrollRatio 數值小於1, 下拉慢, 數值大於1, 下拉速度快setMaxScroll(float scrollRatio)//設置刷新觸發點, 拖拽距離超過此值, 即滿足刷新條件//默認值為刷新控制項的高度setRefreshY(int refreshY)//設置是否響應刷新操作setRefreshState(boolean mRefreshState)------------------上拉載入api--------------------//判斷是否載入中public boolean isLoading()//設置上拉載入觸發點, 上拉距離超過此值, 即滿足載入條件//@param loadY 默認值為載入控制項的高度public void setLoadY(int loadY)//限制上拉載入時最大拖拽距離//@param max 值<0 表示不限制拖拽距離public void setLoadMaxScroll(int max)//設置載入狀態public void setLoading(boolean loading)

如果此項目對你有幫助, 可以star一下, 如果有bug 歡迎lssues, 代碼定期維護, 也會添加新的功能

推薦閱讀:

你怎麼看 堅果手機內置觸寶電話?
Android 開發你需要了解的 Gradle 配置
vivo X9 Plus性能怎麼樣?
金屬後蓋手機怎麼實現nfc?

TAG:Android |