人所缺少的不是才幹而是志向,不是成功的能力而是勤勞的意志。 —— 部爾衛javascript
前幾天分享了兩篇Material Design控件使用的文章,這裏就很少作敘述,下面是傳送門,想要學習的小夥伴能夠去看下:java
juejin.im/entry/58d8d…
juejin.im/entry/58d9c…android
這是一個下拉刷新上拉加載更多框架,頭部用的秋哥的android-Ultra-Pull-To-Refresh,底部和沒有數據的狀態本身實現的。git
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}複製代碼
dependencies {
//compile 'com.github.tengyukun:pulltorefreshRecylerView:v1.0'
//更新解決當列表只有一頁數據的時候,底部的 footer 加載中沒法隱藏
//compile 'com.github.tengyukun:pulltorefreshRecylerView:v1.1'
//添加header隱藏/顯示方法
compile 'com.github.tengyukun:pulltorefreshRecylerView:v1.2'
}複製代碼
app:emply_layout
沒有數據時候佈局github
app:number_load_more
最後可見條目 + number_load_more > total 觸發加載更多;默認值爲4app
<com.pulltorefresh.tyk.library.PtrDefRecyclerView
android:id="@+id/prv_fragmentthree_content"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:emply_layout="@layout/erv_default_empty"
app:number_load_more="5"/>複製代碼
基本設置框架
prv_fragmentthree_content.setAdapter(rvAdapter = new RvAdapter());//設置adapter
prv_fragmentthree_content.setLastUpdateTimeRelateObject(this);//傳入參數類名做爲記錄刷新時間key
prv_fragmentthree_content.setOnRefreshListener(this);//設置刷新監聽
prv_fragmentthree_content.setOnLoadListener(this);//設置加載更多監聽複製代碼
隱藏/顯示空狀態界面maven
prv_fragmentthree_content.hideEmptyView();
prv_fragmentthree_content.showEmptyView();複製代碼
(v1.1更新)隱藏/顯示底部footeride
prv_fragmentthree_content.hideFooterView();
prv_fragmentthree_content.showFooterView();複製代碼
(v1.2更新)隱藏/顯示底部header佈局
prv_fragmentthree_content.hideHeaderView();
prv_fragmentthree_content.showHeaderView();複製代碼
刷新設置
prv_fragmentthree_content.refreshComplete();//下拉刷新結束
prv_fragmentthree_content.loadComplete();//上拉加載結束
prv_fragmentthree_content.loading();//上拉加載顯示"加載中"
prv_fragmentthree_content.loadFail();//上拉加載顯示"加載失敗,點擊重試"
prv_fragmentthree_content.noMore();//上拉加載顯示"暫無更多數據"複製代碼
因爲這裏使用的PtrDefRecyclerView,頭部就是默認經典樣式因此須要調用,使用其餘頭部時不須要調用
prv_fragmentthree_content.setLastUpdateTimeRelateObject(this);//傳入參數類名做爲記錄刷新時間key複製代碼
使用MaterialHeader
MaterialHeader materialHeader = new MaterialHeader(activity);
materialHeader.setPadding(0, 40,0,40);
prv_fragmentthree_content.setHeaderView(materialHeader);
prv_fragmentthree_content.setPinContent(true);複製代碼
//建立ViewHolder
public abstract VH createCustomViewHolder(ViewGroup parent, int viewType);
//ViewHolder設置數據
public abstract void bindCustomViewHolder(VH holder, T t, int position);複製代碼
新增數據
public void add(@NonNull T object)
public void addAll(@NonNull Collection collection)
public void addAll(@NonNull T… items)
public void insert(@NonNull T object, int index)
public void insertAll(@NonNull Collection collection, int index)複製代碼
刪除數據
public void remove(int index)
public boolean remove(@NonNull T object)
public void clear()複製代碼
修改數據
public void update(@NonNull List mDatas)複製代碼
查看數據
public T getItem(int position)
public int getPosition(T item)
public List getData()複製代碼
排序
public void sort(Comparator comparator)複製代碼
加載佈局
public View inflateView(@LayoutRes int resId, ViewGroup parent)複製代碼
頭部吸附效果
mItemDecoration = new StickItemDecoration(context,dataList) {
@Override
public String getTag(int position) {
return "吸附頭部顯示的文字";
}
}
prv_fragmentthree_content.addItemDecoration(mItemDecoration);複製代碼
//設置吸附條目高度
public void setStickHeight(int mStickHeight)
//設置吸附條目背景
public void setStickBackgroundColor(int mStickBackgroundColor)
//設置吸附文字顏色
public void setStickTextColor(int mStickTextColor)
//設置吸附文字大小
public void setStickTextSize(int mStickTextSize)
//設置吸附文字leftmargin
public void setStickTextoffset(int mStickTextoffset)複製代碼
頭部使用秋哥的android-Ultra-Pull-To-Refresh
秋哥默認已經實現了3個頭部
底部的話目前我只實現了一個PtrDefaultFooter,自定義的話須要實現PtrLoadUIHandle接口.寫法能夠參考PtrDefaultFooter
public interface PtrLoadUIHandle {
/** * 容許加載更多 */
int LOAD = 1;
/** * 暫無更多數據 */
int NOMORE = 2;
/** * 加載失敗 */
int LOADFAIL = 3;
/** * @return 獲取底部當前狀態 */
int getState();
void onLoading();//loading狀態實現
void onNoMore();//沒有數據狀態實現
void onLoadFail(OnLoadListener listener);//加載失敗實現
}複製代碼
實現後調用setFooterView()方法設置
前幾天在掘金上看到依然飯特稀西大神寫的Android可伸縮佈局-FlexboxLayout(支持RecyclerView集成),試了一下,非常好用啊,這裏也不作敘述,下面是效果圖和傳送門,樣式有不少想學習的小夥伴能夠去看一下。
Github地址:github.com/tengyukun/p…請你們多多關注,更多更新會首先在GitHub上體現,也會在第一時間在本平臺發佈