Android中github上面一個很好的重新整理庫SmartRefreshLayout
阿新 • • 發佈:2019-01-02
SmartRefreshLayout支援:Listview、GridView、Recyclerview,
甚至TextView等等幾乎所有控制元件的重新整理
使用方法:
1.引入依賴:
compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.4-7'
2.在Application裡面做初始化操作
static { //設定全域性的Header構建器 SmartRefreshLayout.setDefaultRefreshHeaderCreater(new DefaultRefreshHeaderCreater() { @Override public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) { // 設定頭的屬性 ClassicsHeader header = new ClassicsHeader(context); // 設定背景顏色 header.setPrimaryColorId(R.color.C6); // 設定字型顏色 header.setAccentColorId(R.color.wihle); // 設定字型大小 header.setTextSizeTitle(15); return header; } }); //設定全域性的Footer構建器 SmartRefreshLayout.setDefaultRefreshFooterCreater(new DefaultRefreshFooterCreater() { @Override public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) { //指定為經典Footer,預設是 BallPulseFooter //設定腳的屬性 ClassicsFooter footer = new ClassicsFooter(context); // 設定背景顏色 footer.setPrimaryColorId(R.color.C6); // 設定字型顏色 footer.setAccentColorId(R.color.wihle); // 設定字型大小 footer.setTextSizeTitle(15); return footer; } }); }
3.在佈局檔案activity_main.xml中使用
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical" > <com.scwang.smartrefresh.layout.SmartRefreshLayout xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/smartRefreshLayout" android:layout_width="match_parent" android:layout_height="match_parent" app:srlEnablePreviewInEditMode="true"> <!--srlEnablePreviewInEditMode 在編輯模式,開啟和關閉預覽功能--> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@mipmap/mn" android:scaleType="fitXY" /> </com.scwang.smartrefresh.layout.SmartRefreshLayout> </LinearLayout>
4.在MainActivity中使用
package com.zhh.android; import android.app.Activity; import android.os.Bundle; import com.orhanobut.logger.Logger; import com.scwang.smartrefresh.layout.SmartRefreshLayout; import com.scwang.smartrefresh.layout.api.RefreshLayout; import com.scwang.smartrefresh.layout.listener.OnLoadmoreListener; import com.scwang.smartrefresh.layout.listener.OnRefreshListener; public class MainActivity extends Activity { // 這個控制元件極端的強大,連TextView都能使用 private SmartRefreshLayout smartRefreshLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); smartRefreshLayout = (SmartRefreshLayout) findViewById(R.id.smartRefreshLayout); smartRefreshLayout.setEnableRefresh(true);//是否啟用下拉重新整理功能 smartRefreshLayout.setEnableLoadmore(true);//是否啟用上拉載入功能 smartRefreshLayout.setReboundDuration(100);//回彈動畫時長 smartRefreshLayout.setEnableAutoLoadmore(false);//是否啟用列表慣性滑動到底部時自動載入更多 // 下拉重新整理 smartRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(RefreshLayout refreshlayout) { // 重新整理 Logger.t("111").d("下拉重新整理"); smartRefreshLayout.finishRefresh();//結束重新整理 } }); // 上拉載入 smartRefreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() { @Override public void onLoadmore(RefreshLayout refreshlayout) { // 上拉載入 Logger.t("111").d("上拉載入"); smartRefreshLayout.finishLoadmore();//結束載入 } }); } }
原始碼下載:
https://download.csdn.net/download/zhaihaohao1/10850312
github地址:
https://github.com/scwang90/SmartRefreshLayout