SmartRefreshLayout is a "smart" or "smart" pull-down refresh layout. Because of its "intelligence", it not only supports all views, but also supports multiple nested View structures. It inherits from ViewGroup instead of FrameLayout or LinearLayout, improving performance. It also draws on the advantages of various popular refresh layouts, including Google's official SwipeRefreshLayout , other third party's Ultra-Pull-To-Refresh,TwinklingRefreshLayout . It also integrates various cool headers and footers. The goal of SmartRefreshLayout is to build a powerful, stable and mature pull-down refresh framework, and integrate various cool, diverse, practical and beautiful headers and footers.
SmartRefreshLayout official website
Import dependency
Add dependency in build.gradle
//1.1.0 API changes are too large, and old users need to be cautious in upgrading compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-14' compile 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-alpha-14'//No special Header is used. This line can be omitted compile 'com.android.support:appcompat-v7:25.3.1'//Version 23 or higher (required) //1.0.5 when 1.1.0 has problems, it can go back to 1.0.5.1 compile 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.5.1' compile 'com.scwang.smartrefresh:SmartRefreshHeader:1.0.5.1'//No special Header is used. This line can be omitted compile 'com.android.support:appcompat-v7:25.3.1'//Version 23 or higher (required) compile 'com.android.support:design:25.3.1'//Free version (not required, reference can solve the problem of unable to preview)
Use the specified Header and Footer
- Method 1: global setting (the lowest priority will be replaced by the following two methods)
public class App extends Application { //static code segments prevent memory leaks static { //Set global Header builder SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() { @Override public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) { layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);//Global theme color return new ClassicsHeader(context);//. setTimeFormat(new DynamicTimeFormat("updated in% s)); / / specified as classic Header, default is Bezier radar Header } }); //Set up a global Footer builder SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() { @Override public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) { //Specified as classic Footer, the default is BallPulseFooter return new ClassicsFooter(context).setDrawableSize(20); } }); } }
- Method 2 XML layout file (medium priority, will be overwritten by method 3)
<com.scwang.smartrefresh.layout.SmartRefreshLayout xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/refreshLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#444444" app:srlPrimaryColor="#444444" app:srlAccentColor="@android:color/white" app:srlEnablePreviewInEditMode="true"> <!--srlAccentColor srlPrimaryColor Will change Header and Footer Theme colors for--> <!--srlEnablePreviewInEditMode Preview can be turned on and off--> <com.scwang.smartrefresh.layout.header.ClassicsHeader android:layout_width="match_parent" android:layout_height="wrap_content"/> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:padding="@dimen/padding_common" android:background="@android:color/white" android:text="@string/description_define_in_xml"/> <com.scwang.smartrefresh.layout.footer.ClassicsFooter android:layout_width="match_parent" android:layout_height="wrap_content"/> </com.scwang.smartrefresh.layout.SmartRefreshLayout>
- Method 3 Java code setting (highest priority)
final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout); //Set Header to Bessel radar style refreshLayout.setRefreshHeader(new BezierRadarHeader(this).setEnableHorizontalDrag(true)); //Set Footer as ball pulse style refreshLayout.setRefreshFooter(new BallPulseFooter(this).setSpinnerStyle(SpinnerStyle.Scale));
Various effects and display operation modes
1. Default use
Layout: the root layout is LinearLayout, and SmartRefreshLayout directly wraps a RecyclerView
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <com.scwang.smartrefresh.layout.SmartRefreshLayout android:id="@+id/refreshLayout" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#fff" android:overScrollMode="never" /> </com.scwang.smartrefresh.layout.SmartRefreshLayout> </LinearLayout>
Code: set refresh listening. The pull-down refresh function is on by default: mRefreshLayout.setEnableRefresh(true);
RefreshLayout mRefreshLayout = findViewById(R.id.refreshLayout); mRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(@NonNull RefreshLayout refreshLayout) { List<String> data = initDatas(); Message message = new Message(); message.what = 1 ; message.obj = data ; mHandler.sendMessageDelayed(message,2000); } });
Set load listening. Load more functions are off by default: mRefreshLayout.setEnableLoadMore(false); if set listening, load more functions will be turned on:
RefreshLayout mRefreshLayout = findViewById(R.id.refreshLayout); mRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() { @Override public void onLoadMore(@NonNull RefreshLayout refreshLayout) { List<String> data = initDatas(); Message message = new Message(); message.what = 2; message.obj = data ; mHandler.sendMessageDelayed(message,2000); } });
private Handler mHandler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { switch (msg.what){ case 1: //Refresh loading List<String> mList = (List<String>) msg.obj; mRefreshLayout.finishRefresh(true); adapter.setDatas(mList); break; case 2: //Load more List<String> mLoadMoreDatas = (List<String>) msg.obj; mRefreshLayout.finishLoadMore(true); adapter.addMoreValue(mLoadMoreDatas); break; } return false; } });
Display effect:
Refresh.png
Pull up load.png
2. Classic style
layout
<com.scwang.smartrefresh.layout.SmartRefreshLayout android:id="@+id/refreshLayout" android:layout_width="match_parent" android:layout_height="match_parent"> <com.scwang.smartrefresh.layout.header.ClassicsHeader 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="match_parent" android:background="#fff" android:overScrollMode="never" /> <com.scwang.smartrefresh.layout.footer.ClassicsFooter android:layout_width="match_parent" android:layout_height="wrap_content" app:srlClassicsSpinnerStyle="Translate"/> </com.scwang.smartrefresh.layout.SmartRefreshLayout>
Classic.png
You can set various attributes as required;
Note: when setting attributes, sp is used for text size in the code, so it is necessary to change the settings for special needs:
If the implementation mode does not change with the font size of the system, or dp is set by itself: ((textview) header.findviewbyid (classicsheader. ID [text] title)). Settextsize (typedvalue. Complex \\\\\\\\\;
3. False Header is used to fill in the RefreshLayout with the false false Header when the real Header is outside the RefreshLayout. Refer to the paper plane for specific usage;
The effect of using FalsifyHead alone is that a blank drop-down layout will appear during drop-down, which can also be monitored:
The fallifyfooter pull-up loading is the same as the fallifyheader's blank background effect, which can pull the monitor
4. The custom Header can refer to the use of - Custom in Demo
5. Head twolevelheader on the second floor of Taobao, refer to the actual combat in demo - Taobao second floor
The following is a special style header, which needs to be referenced: com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-alpha-14
6. Flight balloon: DeliveryHeader
7. Drop box: DropBoxHeader
8. Full screen water drop: WaveSwipeHeader
9. Official drop-down method: MaterialHeader
10. Color flicker gradient head: StoreHouseHeader
11. War City game header: FunGameBattleCityHeader
12. Brick game: FunGameHitBlockHeader
13. Pop up circle load: BezierCircleHeader
14. Soar to the sky: TaurusHeader
15. Golden Campus: Phoenix header
Some attribute setting methods given by the official website
Some property setting methods of code, xml setting and classic
SmartRefreshLayout java Code settings public class RefreshActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { //The value in the following example is equal to the default value RefreshLayout refreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout); refreshLayout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white); refreshLayout.setDragRate(0.5f);//Show pull down height / finger real pull down height = damping effect refreshLayout.setReboundDuration(300);//Rebound animation time (MS) refreshLayout.setHeaderHeight(100);//Header standard height (display pull-down height > = standard height triggers refresh) refreshLayout.setHeaderHeightPx(100);//Ditto - pixels (deleted in V1.1.0) refreshLayout.setFooterHeight(100);//Footer standard height (display pull-up height > = standard height triggers loading) refreshLayout.setFooterHeightPx(100);//Ditto - pixels (deleted in V1.1.0) refreshLayout.setFooterHeaderInsetStart(0);//Set Header start offset 1.0.5 refreshLayout.setFooterHeaderInsetStartPx(0);//Ditto - pixels in 1.0.5 (deleted in V1.1.0) refreshLayout.setFooterFooterInsetStart(0);//Set Footer start offset 1.0.5 refreshLayout.setFooterFooterInsetStartPx(0);//Ditto - pixels in 1.0.5 (deleted in V1.1.0) refreshLayout.setHeaderMaxDragRate(2);//Maximum display drop-down height / Header standard height refreshLayout.setFooterMaxDragRate(2);//Maximum display drop-down height / Footer standard height refreshLayout.setHeaderTriggerRate(1);//Trigger refresh distance to HeaderHeight ratio 1.0.4 refreshLayout.setFooterTriggerRate(1);//Ratio of trigger loading distance to FooterHeight 1.0.4 refreshLayout.setEnableRefresh(true);//Enable drop-down refresh refreshLayout.setEnableLoadMore(false);//Whether pull-up loading function is enabled refreshLayout.setEnableAutoLoadMore(true);//Do you want to enable list inertial sliding to the bottom to automatically load more refreshLayout.setEnablePureScrollMode(false);//Whether to enable pure scrolling mode refreshLayout.setEnableNestedScroll(false);//Enable nested scrolling or not refreshLayout.setEnableOverScrollBounce(true);//Enable cross boundary rebound refreshLayout.setEnableScrollContentWhenLoaded(true);//Whether to scroll the list to display new content when loading is completed refreshLayout.setEnableHeaderTranslationContent(true);//Pan down the list or content when you drop down the Header or not refreshLayout.setEnableFooterTranslationContent(true);//Do you want to pan up the list or content when you pull up the Footer refreshLayout.setEnableLoadMoreWhenContentNotFull(true);//Whether to enable pull-up loading when the list is less than one page refreshLayout.setEnableFooterFollowWhenLoadFinished(false);//Whether the Footer follows the content 1.0.4 after all loading refreshLayout.setEnableOverScrollDrag(false);//Enable cross boundary drag (apple like effect) 1.0.4 refreshLayout.setEnableScrollContentWhenRefreshed(true);//Whether to scroll the list to display the new content when the refresh is completed 1.0.5 refreshLayout.srlEnableClipHeaderWhenFixedBehind(true);//Whether to trim the Header when the style is FixedBehind 1.0.5 refreshLayout.srlEnableClipFooterWhenFixedBehind(true);//Do you want to trim the Footer when the style is FixedBehind 1.0.5 refreshLayout.setDisableContentWhenRefresh(false);//Whether to disable list operation during refresh refreshLayout.setDisableContentWhenLoading(false);//Whether to disable list operation when loading refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener());//Setting up a multi-function listener refreshLayout.setScrollBoundaryDecider(new ScrollBoundaryDecider());//Set rolling boundary judgment refreshLayout.setScrollBoundaryDecider(new ScrollBoundaryDeciderAdapter());//Custom scroll boundary refreshLayout.setRefreshHeader(new ClassicsHeader(context));//Set Header refreshLayout.setRefreshFooter(new ClassicsFooter(context));//Set Footer refreshLayout.setRefreshContent(new View(context));//Set refresh Content (for non xml layout instead of addView) 1.0.4 refreshLayout.autoRefresh();//auto refresh refreshLayout.autoLoadMore();//Automatic loading refreshLayout.autoRefresh(400);//Auto refresh after 400 ms delay refreshLayout.autoLoadMore(400);//Auto load after 400 ms delay refreshLayout.finishRefresh();//End refresh refreshLayout.finishLoadMore();//End loading refreshLayout.finishRefresh(3000);//End refresh after 3000 ms delay refreshLayout.finishLoadMore(3000);//End load after 3000 ms delay refreshLayout.finishRefresh(false);//End refresh (refresh failed) refreshLayout.finishLoadMore(false);//End load (load failed) refreshLayout.finishLoadMoreWithNoMoreData();//Complete load and mark no more data 1.0.4 refreshLayout.closeHeaderOrFooter();//Close the Header or Footer in the opening state (1.1.0) refreshLayout.resetNoMoreData();//Restore original state 1.0.4 without more data (1.1.0 delete) refreshLayout.setNoMoreData(false);//Restore original state 1.0.5 without more data } } //Global one time setting default properties and default Header public class App extends Application { static {//Using static code snippets can prevent memory leaks //Set the global default configuration (the lowest priority will be overridden by other settings) SmartRefreshLayout.setDefaultRefreshInitializer(new DefaultRefreshInitializer() { @Override public void initialize(@NonNull Context context, @NonNull RefreshLayout layout) { //Start setting global basic parameters (can be overridden by DefaultRefreshHeaderCreator below) layout.setReboundDuration(1000); layout.setReboundInterpolator(new DropBounceInterpolator()); layout.setFooterHeight(100); layout.setDisableContentWhenLoading(false); layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white); } }); //Global settings default Header SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() { @Override public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) { //Start to set the global basic parameters (the properties set here are only bound to the following MaterialHeader, other headers will not take effect, and can override the DefaultRefreshInitializer properties and Xml properties) layout.setEnableHeaderTranslationContent(false); return new MaterialHeader(context).setColorSchemeResources(R.color.colorRed,R.color.colorGreen,R.color.colorBlue); } }); } } xml Code settings <!-- The value in the following example is equal to the default value --> <com.scwang.smartrefresh.layout.SmartRefreshLayout android:id="@+id/refreshLayout" android:layout_width="match_parent" android:layout_height="match_parent" app:srlAccentColor="@android:color/white" app:srlPrimaryColor="@color/colorPrimary" app:srlReboundDuration="300" app:srlDragRate="0.5" app:srlHeaderMaxDragRate="2" app:srlFooterMaxDragRate="2" app:srlHeaderTriggerRate="1" app:srlFooterTriggerRate="1" app:srlHeaderHeight="100dp" app:srlFooterHeight="100dp" app:srlHeaderInsetStart="0dp" app:srlFooterInsetStart="0dp" app:srlEnableRefresh="true" app:srlEnableLoadMore="true" app:srlEnableAutoLoadMore="true" app:srlEnablePureScrollMode="false" app:srlEnableNestedScrolling="false" app:srlEnableOverScrollDrag="true" app:srlEnableOverScrollBounce="true" app:srlEnablePreviewInEditMode="true" app:srlEnableScrollContentWhenLoaded="true" app:srlEnableScrollContentWhenRefreshed="true" app:srlEnableHeaderTranslationContent="true" app:srlEnableFooterTranslationContent="true" app:srlEnableLoadMoreWhenContentNotFull="false" app:srlEnableFooterFollowWhenLoadFinished="false" app:srlEnableClipHeaderWhenFixedBehind="true" app:srlEnableClipFooterWhenFixedBehind="true" app:srlDisableContentWhenRefresh="false" app:srlDisableContentWhenLoading="false" app:srlFixedFooterViewId="@+id/header_fixed" app:srlFixedHeaderViewId="@+id/footer_fixed" app:srlHeaderTranslationViewId="@+id/header_translation" app:srlFooterTranslationViewId="@+id/footer_translation" /> <!--srlAccentColor:Emphasize color--> <!--srlPrimaryColor:Theme color--> <!--srlEnablePreviewInEditMode:Is it enabled? Android Studio edit xml Preview effect on--> <!--srlFixedFooterViewId:Assign one View Fixed when content list scrolls--> <!--srlFixedHeaderViewId:Assign one View Fixed when content list scrolls--> <!--srlHeaderTranslationViewId:Specify drop down Header Time offset view Id--> <!--srlFooterTranslationViewId:Specified pull up Footer Time offset view Id--> <!--Unspecified: look at the above set Method description-->
ClassicsHeader java Code settings public class RefreshActivity extends Activity { static { ClassicsHeader.REFRESH_HEADER_PULLDOWN = "Drop down to refresh"; ClassicsHeader.REFRESH_HEADER_REFRESHING = "Refresh..."; ClassicsHeader.REFRESH_HEADER_LOADING = "Loading..."; ClassicsHeader.REFRESH_HEADER_RELEASE = "Release refresh now"; ClassicsHeader.REFRESH_HEADER_FINISH = "Refresh finish"; ClassicsHeader.REFRESH_HEADER_FAILED = "refresh failed"; ClassicsHeader.REFRESH_HEADER_SECONDARY = "Release to the second floor"; ClassicsHeader.REFRESH_HEADER_LASTTIME = "Last update M-d HH:mm"; ClassicsHeader.REFRESH_HEADER_LASTTIME = "'Last update' M-d HH:mm"; } @Override protected void onCreate(Bundle savedInstanceState) { ClassicsHeader.REFRESH_HEADER_PULLDOWN = getString(R.string.header_pulldown);//"Drop down to refresh"; ClassicsHeader.REFRESH_HEADER_REFRESHING = getString(R.string.header_refreshing);//"Refreshing..."; ClassicsHeader.REFRESH_HEADER_LOADING = getString(R.string.header_loading);//"Loading..."; ClassicsHeader.REFRESH_HEADER_RELEASE = getString(R.string.header_release);//"Release refresh now"; ClassicsHeader.REFRESH_HEADER_FINISH = getString(R.string.header_finish);//"Refresh complete"; ClassicsHeader.REFRESH_HEADER_FAILED = getString(R.string.header_failed);//"Refresh failed"; ClassicsHeader.REFRESH_HEADER_SECONDARY = getString(R.string.header_secondary);//"Release to the second floor"; ClassicsHeader.REFRESH_HEADER_LASTTIME = getString(R.string.header_lasttime);//"Last updated M-d HH:mm"; ClassicsHeader.REFRESH_HEADER_LASTTIME = getString(R.string.header_lasttime);//"'Last update' M-d HH:mm" //The value in the following example is equal to the default value ClassicsHeader header = (ClassicsHeader)findViewById(R.id.header); header.setAccentColor(android.R.color.white);//Set accent color header.setPrimaryColor(R.color.colorPrimary);//Set theme color header.setTextSizeTitle(16);//Set title text size in sp units header.setTextSizeTitle(16, TypedValue.COMPLEX_UNIT_SP);//Ditto (deleted in version 1.1.0) header.setTextSizeTime(10);//Set time text size in sp units header.setTextSizeTime(10, TypedValue.COMPLEX_UNIT_SP);//Ditto (deleted in version 1.1.0) header.setTextTimeMarginTop(10);//Set the top margin of time text in dp units header.setTextTimeMarginTopPx(10);//Ditto - pixel units (deleted in version 1.1.0) header.setEnableLastTime(true);//Show time or not header.setFinishDuration(500);//Set the dwell time for refresh completion display (set to 0 to turn off the dwell function) header.setDrawableSize(20);//Set the size of both arrows and pictures (dp units) header.setDrawableArrowSize(20);//Set arrow size in dp units header.setDrawableProgressSize(20);//Set the size of the picture in dp units header.setDrawableMarginRight(20);//Set spacing (dp units) between pictures and arrows and text header.setDrawableSizePx(20);//Ditto - pixel units header.setDrawableArrowSizePx(20);//Ditto - pixel units (deleted in version 1.1.0) header.setDrawableProgressSizePx(20);//Ditto - pixel units (deleted in version 1.1.0) header.setDrawableMarginRightPx(20);//Ditto - pixel units (deleted in version 1.1.0) header.setArrowBitmap(bitmap);//Set arrow bitmap (deleted in version 1.1.0) header.setArrowDrawable(drawable);//Set arrow picture header.setArrowResource(R.drawable.ic_arrow);//Set arrow resource header.setProgressBitmap(bitmap);//Set picture bitmap (deleted in version 1.1.0) header.setProgressDrawable(drawable);//Set pictures header.setProgressResource(R.drawable.ic_progress);//Set up picture resources header.setTimeFormat(new DynamicTimeFormat("Last update %s"));//Set time format (time will be updated automatically) header.setLastUpdateText("Last updated 3 seconds ago");//Manually update time text settings (time will not be automatically updated) header.setSpinnerStyle(SpinnerStyle.Translate);//Set move style (not supported: MatchLayout) } } xml Code settings <!-- The value in the following example is equal to the default value --> <com.scwang.smartrefresh.layout.SmartRefreshLayout> <com.scwang.smartrefresh.layout.header.ClassicsHeader android:layout_width="match_parent" android:layout_height="wrap_content" app:srlAccentColor="@android:color/white" app:srlPrimaryColor="@color/colorPrimary" app:srlTextSizeTitle="16sp" app:srlTextSizeTime="10dp" app:srlTextTimeMarginTop="2dp" app:srlEnableLastTime="true" app:srlFinishDuration="500" app:srlDrawableSize="20dp" app:srlDrawableArrowSize="20dp" app:srlDrawableProgressSize="20dp" app:srlDrawableMarginRight="20dp" app:srlDrawableArrow="@drawable/ic_arrow" app:srlDrawableProgress="@drawable/ic_progress" app:srlClassicsSpinnerStyle="Translate"/> </com.scwang.smartrefresh.layout.SmartRefreshLayout>
ClassicsFooter java Code settings public class RefreshActivity extends Activity { static { ClassicsFooter.REFRESH_FOOTER_PULLING = "Pull up to load more"; ClassicsFooter.REFRESH_FOOTER_RELEASE = "Release load now"; ClassicsFooter.REFRESH_FOOTER_REFRESHING = "Refresh..."; ClassicsFooter.REFRESH_FOOTER_LOADING = "Loading..."; ClassicsFooter.REFRESH_FOOTER_FINISH = "Load complete"; ClassicsFooter.REFRESH_FOOTER_FAILED = "Failed to load"; ClassicsFooter.REFRESH_FOOTER_NOTHING = "No more data"; } @Override protected void onCreate(Bundle savedInstanceState) { ClassicsFooter.REFRESH_FOOTER_PULLING = getString(R.string.footer_pulling);//"Pull up to load more"; ClassicsFooter.REFRESH_FOOTER_RELEASE = getString(R.string.footer_release);//"Release load now"; ClassicsFooter.REFRESH_FOOTER_REFRESHING = getString(R.string.footer_refreshing);//"Refreshing..."; ClassicsFooter.REFRESH_FOOTER_LOADING = getString(R.string.footer_loading);//"Loading..."; ClassicsFooter.REFRESH_FOOTER_FINISH = getString(R.string.footer_finish);//"Loading complete"; ClassicsFooter.REFRESH_FOOTER_FAILED = getString(R.string.footer_failed);//"Load failed"; ClassicsFooter.REFRESH_FOOTER_NOTHING = getString(R.string.footer_nothing);//"No more data"; //The value in the following example is equal to the default value ClassicsFooter footer = (ClassicsFooter)findViewById(R.id.footer); footer.setAccentColor(android.R.color.white);//Set accent color footer.setPrimaryColor(R.color.colorPrimary);//Set theme color footer.setTextSizeTitle(16);//Set title text size in sp units footer.setTextSizeTitle(16, TypedValue.COMPLEX_UNIT_SP);//Ditto footer.setFinishDuration(500);//Set the dwell time for refresh completion display footer.setDrawableSize(20);//Set the size of both arrows and pictures (dp units) footer.setDrawableArrowSize(20);//Set arrow size in dp units footer.setDrawableProgressSize(20);//Set the size of the picture in dp units footer.setDrawableMarginRight(20);//Set spacing (dp units) between pictures and arrows and text footer.setDrawableSizePx(20);//Ditto - pixel units (deleted in version 1.1.0) footer.setDrawableArrowSizePx(20);//Ditto - pixel units (deleted in version 1.1.0) footer.setDrawableProgressSizePx(20);//Ditto - pixel units (deleted in version 1.1.0) footer.setDrawableMarginRightPx(20);//Ditto - pixel units (deleted in version 1.1.0) footer.setArrowBitmap(bitmap);//Set arrow bitmap (deleted in version 1.1.0) footer.setArrowDrawable(drawable);//Set arrow picture footer.setArrowResource(R.drawable.ic_arrow);//Set arrow resource footer.setProgressBitmap(bitmap);//Set picture bitmap (deleted in version 1.1.0) footer.setProgressDrawable(drawable);//Set pictures footer.setProgressResource(R.drawable.ic_progress);//Set up picture resources footer.setSpinnerStyle(SpinnerStyle.Translate);//Set move style (not supported: MatchLayout) } } xml Code settings <!-- The value in the following example is equal to the default value --> <com.scwang.smartrefresh.layout.SmartRefreshLayout> <com.scwang.smartrefresh.layout.header.ClassicsFooter android:layout_width="match_parent" android:layout_height="wrap_content" app:srlAccentColor="@android:color/white" app:srlPrimaryColor="@color/colorPrimary" app:srlTextSizeTitle="16sp" app:srlFinishDuration="500" app:srlDrawableSize="20dp" app:srlDrawableArrowSize="20dp" app:srlDrawableProgressSize="20dp" app:srlDrawableMarginRight="20dp" app:srlDrawableArrow="@drawable/ic_arrow" app:srlDrawableProgress="@drawable/ic_progress" app:srlClassicsSpinnerStyle="Translate"/> </com.scwang.smartrefresh.layout.SmartRefreshLayout>
Attribute table
Attributes
name | format | description |
---|---|---|
srlPrimaryColor | color | Theme color |
srlAccentColor | color | Emphasize color |
srlReboundDuration | integer | Rebound animation time after release (default 250 ms) |
srlHeaderHeight | dimension | Standard height of Header (dp) |
srlFooterHeight | dimension | Standard height of Footer (dp) |
srlHeaderInsetStart | dimension | Header start offset (dp) V1.0.5 |
srlFooterInsetStart | dimension | Footer's starting offset (dp) V1.0.5 |
srlDragRate | float | Show drag height / true drag height (default 0.5, damping effect) |
srlHeaderMaxDragRate | float | Maximum drag height of Header / standard height of Header (default 2, requirement > = 1) |
srlFooterMaxDragRate | float | Footer maximum drag height / footer standard height (default 2, requirement > = 1) |
srlHeaderTriggerRate | float | Ratio of Header trigger refresh distance to HeaderHeight (default 1) |
srlFooterTriggerRate | float | Ratio of Footer trigger loading distance to FooterHeight (default 1) |
srlEnableRefresh | boolean | Enable pull-down refresh (default true) |
srlEnableLoadMore | boolean | Whether to enable plus pull-up loading function (default: false - smart on) |
srlEnableAutoLoadMore | boolean | Whether to listen to the list inertial scroll to the bottom to trigger the load event (default true) |
srlEnableHeaderTranslationContent | boolean | Whether to drag content at the same time when dragging the Header (true by default) |
srlEnableFooterTranslationContent | boolean | Whether to drag content at the same time when dragging Footer (default true) |
srlEnablePreviewInEditMode | boolean | Whether to display preview effect when editing mode (true by default) |
srlEnablePureScrollMode | boolean | Whether to turn on pure scrolling mode (default false - only one subview is supported when it is turned on) |
srlEnableOverScrollDrag | boolean | Enable cross boundary drag (apple like effect) V1.0.4 |
srlEnableOverScrollBounce | boolean | Set whether to enable the rebound function beyond the boundary (true by default) |
srlEnableNestedScrolling | boolean | Enable nested scrolling (default false - smart on) |
srlEnableScrollContentWhenLoaded | boolean | Whether to scroll content to display new data after loading (default - true) |
srlEnableScrollContentWhenRefreshed | boolean | Whether to scroll the content to display new data after the refresh is successful (default - true) |
srlEnableLoadMoreWhenContentNotFull | boolean | When the content is less than one page, can you pull up to load more (default - false) |
srlEnableFooterFollowWhenLoadFinished | boolean | Whether the Footer follows the content after all loading |
srlEnableClipHeaderWhenFixedBehind | boolean | Whether to trim the Header when the style is FixedBehind V1.0.5 |
srlEnableClipFooterWhenFixedBehind | boolean | Do you want to trim the Footer when the style is FixedBehind V1.0.5 |
srlDisableContentWhenRefresh | boolean | Whether to disable all gesture operations of content when refreshing (default false) |
srlDisableContentWhenLoading | boolean | Whether to disable all gesture operations of content when loading (default false) |
srlFixedHeaderViewId | id | Specify the view Id for the fixed top |
srlFixedFooterViewId | id | Specify the view Id for the fixed bottom |
srlHeaderTranslationViewId | id | Specifies the view Id to offset when dropping down the Header |
srlFooterTranslationViewId | id | Specifies the view Id of the offset when the Footer is pulled up |
Method
name | format | description |
---|---|---|
setPrimaryColors | colors | Theme \ accent color |
setPrimaryColorsId | colors | Theme \ accent resource Id |
setReboundDuration | integer | Rebound animation time after release (default 250 ms) |
setHeaderHeight | dimension | Standard height of Header (px/dp versions) |
setFooterHeight | dimension | Standard height of Footer (px/dp versions) |
setHeaderInsetStart | dimension | Header start offset (px/dp versions) V1.0.5 |
setFooterInsetStart | dimension | Footer start offset (px/dp versions) V1.0.5 |
setDragRate | float | Show drag height / true drag height (default 0.5, damping effect) |
setHeaderMaxDragRate | float | Maximum drag height of Header / standard height of Header (default 2, requirement > = 1) |
setFooterMaxDragRate | float | Footer maximum drag height / footer standard height (default 2, requirement > = 1) |
setHeaderTriggerRate | float | Ratio of Header trigger refresh distance to HeaderHeight (default 1) |
setFooterTriggerRate | float | Ratio of Footer trigger loading distance to FooterHeight (default 1) |
setEnableRefresh | boolean | Enable pull-down refresh (default true) |
setEnableLoadMore | boolean | Whether to enable plus pull loading function (default false - smart on) |
setEnableHeaderTranslationContent | boolean | Whether to drag content at the same time when dragging the Header (true by default) |
setEnableFooterTranslationContent | boolean | Whether to drag content at the same time when dragging Footer (default true) |
setEnableAutoLoadMore | boolean | Whether to listen to the list inertial scroll to the bottom to trigger the load event (default true) |
setEnablePureScrollMode | boolean | Whether to turn on pure scrolling mode (default false - only one subview is supported when it is turned on) |
setEnableOverScrollDrag | boolean | Enable cross boundary drag (apple like effect) V1.0.4 |
setEnableOverScrollBounce | boolean | Set whether to enable the rebound function beyond the boundary (true by default) |
setEnableNestedScrolling | boolean | Enable nested scrolling (default false - smart on) |
setEnableScrollContentWhenLoaded | boolean | Whether to scroll content to display new data after loading (default - true) |
setEnableScrollContentWhenRefreshed | boolean | Whether to scroll the content to display new data after the refresh is successful (default - true) V1.0.5 |
setEnableLoadMoreWhenContentNotFull | boolean | When the content is less than one page, can you pull up to load more (default - false) |
setEnableFooterFollowWhenLoadFinished | boolean | Whether the Footer follows the content after all loading |
setEnableClipHeaderWhenFixedBehind | boolean | Whether to trim the Header when the style is FixedBehind V1.0.5 |
setEnableClipFooterWhenFixedBehind | boolean | Do you want to trim the Footer when the style is FixedBehind V1.0.5 |
setDisableContentWhenRefresh | boolean | Whether to disable all gesture operations of content when refreshing (default false) |
setDisableContentWhenLoading | boolean | Whether to disable all gesture operations of content when loading (default false) |
setReboundInterpolator | Interpolator | Interpolator for springback animation (default deceleration) |
setRefreshHeader | RefreshHeader | Set specified Header (default Bezier radar) |
setRefreshFooter | RefreshFooter | Set the specified Footer (default ball pulse) |
setRefreshContent | View | Set refresh Content (used to dynamically replace empty layout) |
setOnRefreshListener | OnRefreshListener | Set refresh listener (not set, turn off refresh in 3 seconds by default) |
setOnLoadMoreListener | OnLoadMoreListener | Set load listener (not set, turn off load in 3 seconds by default) |
setOnRefreshLoadMoreListener | OnRefreshLoadMoreListener | Set the above two monitors at the same time |
setOnMultiPurposeListener | OnMultiPurposeListener | Setting up a multi-function listener |
setLoadMoreFinished | boolean | Set all data loading completed, and no loading event will be triggered after that |
setScrollBoundaryDecider | boundary | Set rolling boundary judgment |
finishRefresh | (int delayed) | Finish refreshing, finish refreshing animation |
finishLoadMore | (int delayed) | Finish loading, finish loading animation |
finishRefresh | (boolean success) | Complete refresh and set success |
finishLoadMore | (boolean success) | Finish loading and set success |
finishLoadMoreWithNoMoreData | Complete load and mark no more data (V1.0.4) | |
closeHeaderOrFooter | Close Header or Footer (1.1.0) | |
resetNoMoreData | V1.0.4 (deleted in V1.1.0, replaced by setNoMoreData(false)) | |
setNoMoreData | boolean | Set more data status V1.0.5 |
getRefreshHeader | RefreshHeader | Get Header |
getRefreshFooter | RefreshFooter | Get Footer |
getState | RefreshState | Get current status |
isRefreshing | boolean | (deleted in V1.1.0, instead of getState==Refreshing) |
isLoading | boolean | (deleted in V1.1.0, instead of getState==Loading) |
autoRefresh | (int delayed) | Trigger auto refresh |
autoLoadMore | (int delayed) | Trigger auto load |
Header-Attributes
name | format | description |
---|---|---|
srlPrimaryColor | color | Theme color |
srlAccentColor | color | Emphasize color |
srlDrawableArrow | drawable | Arrow pictures |
srlDrawableProgress | drawable | Rotate picture |
srlClassicsSpinnerStyle | enum | Transform styles: translate, Scale, FixedBehind |
srlSpinnerStyle | enum | Transform style: all, FixedFront (fixed in front or full screen) of srlClassicsSpinnerStyle |
srlFinishDuration | int | At the end of the animation, displays the time in milliseconds for the completion state to stay |
srlEnableLastTime | boolean | Display last update time (default true) |
srlDrawableMarginRight | dimension | Distance between picture and right text (default: 20dp) |
srlTextTimeMarginTop | dimension | Distance between update time and above title (default 2dp) |
srlTextSizeTitle | dimension | Title text size (default 16sp) |
srlTextSizeTime | dimension | Time text size (default 12sp) |
Header-Method
name | format | description |
---|---|---|
setPrimaryColor | color | Theme color |
setAccentColor | color | Emphasize color |
setArrowDrawable | drawable | Set arrow picture |
setProgressDrawable | drawable | Set rotation picture |
setArrowBitmap | bitmap | Set arrow picture (deleted in V1.1.0) |
setProgressBitmap | bitmap | Set rotation picture (deleted in V1.1.0) |
setArrowResource | int | Set arrow picture |
setProgressResource | int | Set rotation picture |
setSpinnerStyle | enum | Transform style: reference property srlSpinnerStyle |
setClassicsSpinnerStyle | enum | Transform style: reference property srlClassicsSpinnerStyle |
setFinishDuration | int | At the end of the animation, the time in milliseconds for the completion status to stay is displayed |
setEnableLastTime | boolean | Display last update time (default true) |
setTextSizeTitle | dimension | Title text size (default 16sp) |
setTextSizeTime | dimension | Time text size (default 12sp) |
setLastUpdateText | string | Set the update time manually, the time will not be updated automatically |