### SmartRefreshLayout - Header and Footer Customization
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
Methods to set custom refresh headers and footers, and to configure the refresh content view.
```Java
setRefreshHeader(RefreshHeader header);
setRefreshFooter(RefreshFooter footer);
setRefreshContent(View content);
```
--------------------------------
### Add srlFooterInsetStart Attribute
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_update.md
Adds the `srlFooterInsetStart` attribute and its method, potentially for setting start inset values for footers.
```Java
add: srlFooterInsetStart 属性和对应方法
```
--------------------------------
### SmartRefreshLayout - Listener and Callback Configuration
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
Methods for setting listeners to handle refresh and load more events, including single listeners for both or a multi-purpose listener.
```Java
setOnRefreshListener(OnRefreshListener listener);
setOnLoadMoreListener(OnLoadMoreListener listener);
setOnRefreshLoadMoreListener(OnRefreshLoadMoreListener listener);
setOnMultiListener(OnMultiPurposeListener listener);
```
--------------------------------
### SmartRefreshLayout - Animation and Duration Control
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
Methods to configure animation durations, rebound behavior, and control how content is translated during header/footer interactions.
```Java
setReboundDuration(int duration);
setHeaderHeight(int height);
setFooterHeight(int height);
setDragRate(float rate);
setHeaderMaxDragRate(float rate);
setFooterMaxDragRate(float rate);
setHeaderTriggerRate(float rate);
setFooterTriggerRate(float rate);
setEnableHeaderTranslationContent(boolean enable);
setEnableFooterTranslationContent(boolean enable);
setEnableOverScrollDrag(boolean enable);
setEnableOverScrollBounce(boolean enable);
```
--------------------------------
### Add srlHeaderInsetStart Attribute
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_update.md
Introduces the `srlHeaderInsetStart` attribute and its corresponding method, likely for setting start inset values for headers.
```Java
add: srlHeaderInsetStart 属性和对应方法
```
--------------------------------
### SmartRefreshLayout - Theme and Color Configuration
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
Methods to set primary and accent colors for the refresh layout, and methods to set these colors using resource IDs.
```Java
setPrimaryColors(int... colors);
setPrimaryColorsId(int... ids);
```
--------------------------------
### SmartRefreshLayout - State Management and Completion
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
Methods to finish refresh or load more operations, optionally with success status, and to manage the 'no more data' state.
```Java
finishRefresh();
finishLoadMore();
finishRefresh(boolean success);
finishLoadMore(boolean success);
finishLoadMoreWithNoMoreData();
setNoMoreData(boolean noMoreData);
```
--------------------------------
### Basic SmartRefreshLayout Initialization (Java)
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/README_EN.md
This snippet demonstrates the basic initialization of SmartRefreshLayout in an Android application using Java. It shows how to set the refresh header and footer, and enable features like enabling the header and footer. This is a fundamental setup for using the library.
```Java
SmartRefreshLayout refreshLayout = (SmartRefreshLayout) findViewById(R.id.refreshLayout);
refreshLayout.setRefreshHeader(new ClassicsHeader(this));
refreshLayout.setRefreshFooter(new ClassicsFooter(this));
refreshLayout.setEnableRefresh(true);
refreshLayout.setEnableLoadMore(true);
```
--------------------------------
### SmartRefreshLayout - Header Methods
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
Methods to programmatically set properties of the refresh header, such as colors, drawables, spinner styles, and text configurations.
```Java
header.setPrimaryColor(color);
header.setAccentColor(color);
header.setArrowDrawable(drawable);
header.setProgressDrawable(drawable);
header.setArrowResource(resId);
header.setProgressResource(resId);
header.setSpinnerStyle(SpinnerStyle.Translate);
header.setClassicsSpinnerStyle(ClassicsSpinnerStyle.Scale);
header.setFinishDuration(duration);
header.setEnableLastTime(enable);
header.setTextSizeTitle(size);
header.setTextSizeTime(size);
header.setLastUpdateText(text);
```
--------------------------------
### Configure ClassicsFooter via XML Attributes
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
This XML code shows how to configure the ClassicsFooter directly within the layout file using various attributes. It allows setting text, colors, sizes, drawable resources for arrows and progress indicators, and the spinner style.
```xml
```
--------------------------------
### Configure ClassicsFooter Text and Appearance in Java
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
This Java code demonstrates how to set various text strings (e.g., pulling, releasing, refreshing) and appearance properties (colors, sizes, drawables, spinner style) for the ClassicsFooter. It shows both static initialization and runtime configuration within an Activity's onCreate method.
```java
public class RefreshActivity extends Activity {
static {
ClassicsFooter.REFRESH_FOOTER_PULLING = "上拉加载更多";
ClassicsFooter.REFRESH_FOOTER_RELEASE = "释放立即加载";
ClassicsFooter.REFRESH_FOOTER_REFRESHING = "正在刷新...";
ClassicsFooter.REFRESH_FOOTER_LOADING = "正在加载...";
ClassicsFooter.REFRESH_FOOTER_FINISH = "加载完成";
ClassicsFooter.REFRESH_FOOTER_FAILED = "加载失败";
ClassicsFooter.REFRESH_FOOTER_NOTHING = "没有更多数据了";
}
@Override
protected void onCreate(Bundle savedInstanceState) {
ClassicsFooter.REFRESH_FOOTER_PULLING = getString(R.string.footer_pulling);//"上拉加载更多";
ClassicsFooter.REFRESH_FOOTER_RELEASE = getString(R.string.footer_release);//"释放立即加载";
ClassicsFooter.REFRESH_FOOTER_REFRESHING = getString(R.string.footer_refreshing);//"正在刷新...";
ClassicsFooter.REFRESH_FOOTER_LOADING = getString(R.string.footer_loading);//"正在加载...";
ClassicsFooter.REFRESH_FOOTER_FINISH = getString(R.string.footer_finish);//"加载完成";
ClassicsFooter.REFRESH_FOOTER_FAILED = getString(R.string.footer_failed);//"加载失败";
ClassicsFooter.REFRESH_FOOTER_NOTHING = getString(R.string.footer_nothing);//"没有更多数据了";
//下面示例中的值等于默认值
ClassicsFooter footer = (ClassicsFooter)findViewById(R.id.footer);
footer.setAccentColor(android.R.color.white);//设置强调颜色
footer.setPrimaryColor(R.color.colorPrimary);//设置主题颜色
footer.setTextSizeTitle(16);//设置标题文字大小(sp单位)
footer.setTextSizeTitle(16, TypedValue.COMPLEX_UNIT_SP);//同上
footer.setFinishDuration(500);//设置刷新完成显示的停留时间
footer.setDrawableSize(20);//同时设置箭头和图片的大小(dp单位)
footer.setDrawableArrowSize(20);//设置箭头的大小(dp单位)
footer.setDrawableProgressSize(20);//设置图片的大小(dp单位)
footer.setDrawableMarginRight(20);//设置图片和箭头和文字的间距(dp单位)
footer.setDrawableSizePx(20);//同上-像素单位(1.1.0版本删除)
footer.setDrawableArrowSizePx(20);//同上-像素单位(1.1.0版本删除)
footer.setDrawableProgressSizePx(20);//同上-像素单位(1.1.0版本删除)
footer.setDrawableMarginRightPx(20);//同上-像素单位(1.1.0版本删除)
footer.setArrowBitmap(bitmap);//设置箭头位图(1.1.0版本删除)
footer.setArrowDrawable(drawable);//设置箭头图片
footer.setArrowResource(R.drawable.ic_arrow);//设置箭头资源
footer.setProgressBitmap(bitmap);//设置图片位图(1.1.0版本删除)
footer.setProgressDrawable(drawable);//设置图片
footer.setProgressResource(R.drawable.ic_progress);//设置图片资源
footer.setSpinnerStyle(SpinnerStyle.Translate);//设置移动样式(不支持:MatchLayout)
}
}
```
--------------------------------
### SmartRefreshLayout - Auto Refresh and Load More
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
Methods to trigger automatic refresh or load more operations with an optional delay, and to trigger animations without performing the actual refresh/load.
```Java
autoRefresh(int delayed);
autoLoadMore(int delayed);
autoRefreshAnimationOnly();
autoLoadMoreAnimationOnly();
```
--------------------------------
### Configure ClassicsHeader in XML
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
This XML code demonstrates how to configure the ClassicsHeader using layout attributes within a SmartRefreshLayout. It covers properties like accent color, primary color, text sizes, drawable resources, and spinner styles.
```xml
```
--------------------------------
### SmartRefreshLayout XML Configuration
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
This XML code provides a comprehensive configuration for SmartRefreshLayout, defining attributes such as accent and primary colors, drag rates, header/footer heights, and various enabling/disabling options for refresh, load more, and scrolling behaviors.
```xml
```
--------------------------------
### SmartRefreshLayout - Header Attributes
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
XML attributes for customizing the appearance and behavior of the refresh header, including colors, drawables, text styles, and spinner animations.
```XML
app:srlPrimaryColor="@color/colorPrimary"
app:srlAccentColor="@color/colorAccent"
app:srlDrawableArrow="@drawable/ic_arrow"
app:srlDrawableProgress="@drawable/ic_progress"
app:srlClassicsSpinnerStyle="Translate"
app:srlSpinnerStyle="FixedBehind"
app:srlFinishDuration="500"
app:srlEnableLastTime="true"
app:srlDrawableMarginRight="16dp"
app:srlTextTimeMarginTop="2dp"
app:srlTextSizeTitle="18sp"
app:srlTextSizeTime="14sp">
```
--------------------------------
### Configure ClassicsHeader in Java
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
This Java code demonstrates how to set various properties of the ClassicsHeader, including text strings, colors, sizes, and animation styles. It shows how to access and modify these properties programmatically within an Android Activity.
```java
public class RefreshActivity extends Activity {
static {
ClassicsHeader.REFRESH_HEADER_PULLDOWN = "下拉可以刷新";
ClassicsHeader.REFRESH_HEADER_REFRESHING = "正在刷新...";
ClassicsHeader.REFRESH_HEADER_LOADING = "正在加载...";
ClassicsHeader.REFRESH_HEADER_RELEASE = "释放立即刷新";
ClassicsHeader.REFRESH_HEADER_FINISH = "刷新完成";
ClassicsHeader.REFRESH_HEADER_FAILED = "刷新失败";
ClassicsHeader.REFRESH_HEADER_SECONDARY = "释放进入二楼";
ClassicsHeader.REFRESH_HEADER_LASTTIME = "上次更新 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);//"下拉可以刷新";
ClassicsHeader.REFRESH_HEADER_REFRESHING = getString(R.string.header_refreshing);//"正在刷新...";
ClassicsHeader.REFRESH_HEADER_LOADING = getString(R.string.header_loading);//"正在加载...";
ClassicsHeader.REFRESH_HEADER_RELEASE = getString(R.string.header_release);//"释放立即刷新";
ClassicsHeader.REFRESH_HEADER_FINISH = getString(R.string.header_finish);//"刷新完成";
ClassicsHeader.REFRESH_HEADER_FAILED = getString(R.string.header_failed);//"刷新失败";
ClassicsHeader.REFRESH_HEADER_SECONDARY = getString(R.string.header_secondary);//"释放进入二楼";
ClassicsHeader.REFRESH_HEADER_LASTTIME = getString(R.string.header_lasttime);//"上次更新 M-d HH:mm";
ClassicsHeader.REFRESH_HEADER_LASTTIME = getString(R.string.header_lasttime);//"'Last update' M-d HH:mm"
//下面示例中的值等于默认值
ClassicsHeader header = (ClassicsHeader)findViewById(R.id.header);
header.setAccentColor(android.R.color.white);//设置强调颜色
header.setPrimaryColor(R.color.colorPrimary);//设置主题颜色
header.setTextSizeTitle(16);//设置标题文字大小(sp单位)
header.setTextSizeTitle(16, TypedValue.COMPLEX_UNIT_SP);//同上(1.1.0版本删除)
header.setTextSizeTime(10);//设置时间文字大小(sp单位)
header.setTextSizeTime(10, TypedValue.COMPLEX_UNIT_SP);//同上(1.1.0版本删除)
header.setTextTimeMarginTop(10);//设置时间文字的上边距(dp单位)
header.setTextTimeMarginTopPx(10);//同上-像素单位(1.1.0版本删除)
header.setEnableLastTime(true);//是否显示时间
header.setFinishDuration(500);//设置刷新完成显示的停留时间(设为0可以关闭停留功能)
header.setDrawableSize(20);//同时设置箭头和图片的大小(dp单位)
header.setDrawableArrowSize(20);//设置箭头的大小(dp单位)
header.setDrawableProgressSize(20);//设置图片的大小(dp单位)
header.setDrawableMarginRight(20);//设置图片和箭头和文字的间距(dp单位)
header.setDrawableSizePx(20);//同上-像素单位
header.setDrawableArrowSizePx(20);//同上-像素单位(1.1.0版本删除)
header.setDrawableProgressSizePx(20);//同上-像素单位(1.1.0版本删除)
header.setDrawableMarginRightPx(20);//同上-像素单位(1.1.0版本删除)
header.setArrowBitmap(bitmap);//设置箭头位图(1.1.0版本删除)
header.setArrowDrawable(drawable);//设置箭头图片
header.setArrowResource(R.drawable.ic_arrow);//设置箭头资源
header.setProgressBitmap(bitmap);//设置图片位图(1.1.0版本删除)
header.setProgressDrawable(drawable);//设置图片
header.setProgressResource(R.drawable.ic_progress);//设置图片资源
header.setTimeFormat(new DynamicTimeFormat("上次更新 %s"));//设置时间格式化(时间会自动更新)
header.setLastUpdateText("上次更新 3秒前");//手动更新时间文字设置(将不会自动更新时间)
header.setSpinnerStyle(SpinnerStyle.Translate);//设置移动样式(不支持:MatchLayout)
}
}
```
--------------------------------
### Implement RefreshHeader Interface
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_custom.md
This Java code defines the `RefreshHeader` interface, which is the fundamental contract for creating custom header components in SmartRefreshLayout. It outlines methods for getting the view, specifying the spinner style, setting colors, initialization, starting and finishing animations, and handling pull and release events.
```Java
public interface RefreshHeader {
/**
* 获取真实视图(必须返回,不能为null)
*/
@NonNull
View getView();
/**
* 获取变换方式(必须指定一个:平移、拉伸、固定、全屏)
*/
SpinnerStyle getSpinnerStyle();
/**
* 设置主题颜色 (如果自定义的Header没有注意颜色,本方法可以什么都不处理)
* @param colors 对应Xml中配置的 srlPrimaryColor srlAccentColor
*/
void setPrimaryColors(@ColorInt int ... colors);
/**
* 尺寸定义初始化完成 (如果高度不改变(代码修改:setHeader),只调用一次, 在RefreshLayout#onMeasure中调用)
* @param kernel RefreshKernel 核心接口(用于完成高级Header功能)
* @param height HeaderHeight or FooterHeight
* @param maxDragHeight 最大拖动高度
*/
void onInitialized(RefreshKernel kernel, int height, int maxDragHeight);
/**
* 开始动画(开始刷新或者开始加载动画)
* @param layout RefreshLayout
* @param height HeaderHeight or FooterHeight
* @param maxDragHeight 最大拖动高度
*/
void onStartAnimator(RefreshLayout layout, int height, int maxDragHeight);
/**
* 动画结束
* @param layout RefreshLayout
* @param success 数据是否成功刷新或加载
* @return 完成动画所需时间 如果返回 Integer.MAX_VALUE 将取消本次完成事件,继续保持原有状态
*/
int onFinish(RefreshLayout layout, boolean success);
/**
* 手指拖动下拉(会连续多次调用,用于实时控制动画关键帧)
* @param percent 下拉的百分比 值 = offset/headerHeight (0 - percent - (headerHeight+maxDragHeight) / headerHeight )
* @param offset 下拉的像素偏移量 0 - offset - (headerHeight+maxDragHeight)
* @param headerHeight Header的高度
* @param maxDragHeight 最大拖动高度
*/
void onPulling(float percent, int offset, int headerHeight, int maxDragHeight);
/**
* 手指释放之后的持续动画(会连续多次调用,用于实时控制动画关键帧)
* @param percent 下拉的百分比 值 = offset/headerHeight (0 - percent - (headerHeight+maxDragHeight) / headerHeight )
* @param offset 下拉的像素偏移量 0 - offset - (headerHeight+maxDragHeight)
* @param headerHeight Header的高度
* @param maxDragHeight 最大拖动高度
*/
void onReleasing(float percent, int offset, int headerHeight, int maxDragHeight);
}
```
--------------------------------
### SmartRefreshLayout - Scroll Boundary and State Retrieval
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
Methods to set a custom scroll boundary decider and to retrieve the current refresh state of the layout.
```Java
setScrollBoundaryDecider(ScrollBoundaryDecider boundary);
getState();
```
--------------------------------
### SmartRefreshLayout - Basic Refresh Control
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
Methods to enable or disable core refresh and load more functionalities, and control the behavior when content is not fully loaded or when refresh/load operations are in progress.
```Java
setEnableRefresh(boolean enable);
setEnableLoadMore(boolean enable);
setEnableAutoLoadMore(boolean enable);
setEnablePureScrollMode(boolean enable);
setEnableScrollContentWhenLoaded(boolean enable);
setEnableScrollContentWhenRefreshed(boolean enable);
setEnableLoadMoreWhenContentNotFull(boolean enable);
setDisableContentWhenRefresh(boolean disable);
setDisableContentWhenLoading(boolean disable);
```
--------------------------------
### Implement Refresh and Load More Listeners in Java
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/README.md
This Java code demonstrates how to set up SmartRefreshLayout in an Activity or Fragment. It includes listeners for pull-down-to-refresh and pull-up-to-load-more actions, with examples of finishing the refresh/load operations.
```Java
RefreshLayout refreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
refreshLayout.setRefreshHeader(new ClassicsHeader(this));
refreshLayout.setRefreshFooter(new ClassicsFooter(this));
refreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(RefreshLayout refreshlayout) {
refreshlayout.finishRefresh(2000/*,false*/);//传入false表示刷新失败
}
});
refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void onLoadMore(RefreshLayout refreshlayout) {
refreshlayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败
}
});
```
--------------------------------
### Customizing Header and Footer Appearance (Kotlin)
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/README_EN.md
This Kotlin example demonstrates customizing the header and footer of SmartRefreshLayout with different visual styles. It uses Kotlin's concise syntax to assign custom header and footer implementations, such as `BezierCircleHeader` and `BallPulseFooter`, for enhanced UI.
```Kotlin
refreshLayout.refreshHeader = BezierCircleHeader(this)
refreshLayout.refreshFooter = BallPulseFooter(this)
```
--------------------------------
### Configure SmartRefreshLayout Properties in Java
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
This snippet shows how to configure various properties of SmartRefreshLayout programmatically in Java. It includes settings for drag rate, rebound duration, header/footer heights, offsets, maximum drag rates, trigger rates, and enabling/disabling various features like refresh, load more, nested scrolling, and overscroll effects.
```java
public class RefreshActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
//下面示例中的值等于默认值
RefreshLayout refreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout);
refreshLayout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);
refreshLayout.setDragRate(0.5f);//显示下拉高度/手指真实下拉高度=阻尼效果
refreshLayout.setReboundDuration(300);//回弹动画时长(毫秒)
refreshLayout.setHeaderHeight(100);//Header标准高度(显示下拉高度>=标准高度 触发刷新)
refreshLayout.setHeaderHeightPx(100);//同上-像素为单位 (V1.1.0删除)
refreshLayout.setFooterHeight(100);//Footer标准高度(显示上拉高度>=标准高度 触发加载)
refreshLayout.setFooterHeightPx(100);//同上-像素为单位 (V1.1.0删除)
refreshLayout.setHeaderInsetStart(0);//设置 Header 起始位置偏移量 1.0.5
refreshLayout.setHeaderInsetStartPx(0);//同上-像素为单位 1.0.5 (V1.1.0删除)
refreshLayout.setFooterInsetStart(0);//设置 Footer 起始位置偏移量 1.0.5
refreshLayout.setFooterInsetStartPx(0);//同上-像素为单位 1.0.5 (V1.1.0删除)
refreshLayout.setHeaderMaxDragRate(2);//最大显示下拉高度/Header标准高度
refreshLayout.setFooterMaxDragRate(2);//最大显示下拉高度/Footer标准高度
refreshLayout.setHeaderTriggerRate(1);//触发刷新距离 与 HeaderHeight 的比率1.0.4
refreshLayout.setFooterTriggerRate(1);//触发加载距离 与 FooterHeight 的比率1.0.4
refreshLayout.setEnableRefresh(true);//是否启用下拉刷新功能
refreshLayout.setEnableLoadMore(false);//是否启用上拉加载功能
refreshLayout.setEnableAutoLoadMore(true);//是否启用列表惯性滑动到底部时自动加载更多
refreshLayout.setEnablePureScrollMode(false);//是否启用纯滚动模式
refreshLayout.setEnableNestedScroll(false);//是否启用嵌套滚动
refreshLayout.setEnableOverScrollBounce(true);//是否启用越界回弹
refreshLayout.setEnableScrollContentWhenLoaded(true);//是否在加载完成时滚动列表显示新的内容
refreshLayout.setEnableHeaderTranslationContent(true);//是否下拉Header的时候向下平移列表或者内容
refreshLayout.setEnableFooterTranslationContent(true);//是否上拉Footer的时候向上平移列表或者内容
refreshLayout.setEnableLoadMoreWhenContentNotFull(true);//是否在列表不满一页时候开启上拉加载功能
refreshLayout.setEnableFooterFollowWhenLoadFinished(false);//是否在全部加载结束之后Footer跟随内容1.0.4
refreshLayout.setEnableOverScrollDrag(false);//是否启用越界拖动(仿苹果效果)1.0.4
refreshLayout.setEnableScrollContentWhenRefreshed(true);//是否在刷新完成时滚动列表显示新的内容 1.0.5
refreshLayout.srlEnableClipHeaderWhenFixedBehind(true);//是否剪裁Header当时样式为FixedBehind时1.0.5
refreshLayout.srlEnableClipFooterWhenFixedBehind(true);//是否剪裁Footer当时样式为FixedBehind时1.0.5
refreshLayout.setDisableContentWhenRefresh(false);//是否在刷新的时候禁止列表的操作
refreshLayout.setDisableContentWhenLoading(false);//是否在加载的时候禁止列表的操作
refreshLayout.setOnMultiListener(new SimpleMultiListener());//设置多功能监听器
refreshLayout.setScrollBoundaryDecider(new ScrollBoundaryDecider());//设置滚动边界判断
refreshLayout.setScrollBoundaryDecider(new SimpleBoundaryDecider());//自定义滚动边界
refreshLayout.setRefreshHeader(new ClassicsHeader(context));//设置Header
refreshLayout.setRefreshFooter(new ClassicsFooter(context));//设置Footer
refreshLayout.setRefreshContent(new View(context));//设置刷新Content(用于非xml布局代替addView)1.0.4
refreshLayout.autoRefresh();//自动刷新
refreshLayout.autoLoadMore();//自动加载
refreshLayout.autoRefreshAnimationOnly();//自动刷新,只显示动画不执行刷新
refreshLayout.autoLoadMoreAnimationOnly();//自动加载,只显示动画不执行加载
refreshLayout.autoRefresh(400);//延迟400毫秒后自动刷新
refreshLayout.autoLoadMore(400);//延迟400毫秒后自动加载
refreshLayout.finishRefresh();//结束刷新
refreshLayout.finishLoadMore();//结束加载
refreshLayout.finishRefresh(3000);//延迟3000毫秒后结束刷新
refreshLayout.finishLoadMore(3000);//延迟3000毫秒后结束加载
refreshLayout.finishRefresh(false);//结束刷新(刷新失败)
refreshLayout.finishLoadMore(false);//结束加载(加载失败)
refreshLayout.finishLoadMoreWithNoMoreData();//完成加载并标记没有更多数据 1.0.4
refreshLayout.closeHeaderOrFooter();//关闭正在打开状态的 Header 或者 Footer(1.1.0)
refreshLayout.resetNoMoreData();//恢复没有更多数据的原始状态 1.0.4(1.1.0删除)
refreshLayout.setNoMoreData(false);//恢复没有更多数据的原始状态 1.0.5
}
}
```
--------------------------------
### XML: SmartRefreshLayout with GIF Header
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_smart.md
This example shows how to implement a dynamic GIF image as a custom header in SmartRefreshLayout. It requires the 'android-gif-drawable' library and configures the GIFImageView as the header.
```XML
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.3'//一个开源gif控件
```
```XML
```
--------------------------------
### Replace Scale Style with FixedBehind
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_update.md
Replaces the `Scale` style in built-in Headers with `FixedBehind`. Users can refer to the demo examples if they need to switch back.
```Java
修改: 将之前自带Header中 Scale 样式全部采用 FixedBehind 代替,用户如需替换可以参考这些demo
```
--------------------------------
### Get SmartRefreshLayout State (Java)
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_faq.md
Illustrates how to retrieve the current state of SmartRefreshLayout using the `getState()` method, which replaces the deprecated `isRefreshing()` and `isLoading()` methods. It shows how to check for idle, loading, refreshing states, and other conditions like dragging, finishing, and header/footer status.
```Java
refreshLayout.getState() == RefreshState.None
refreshLayout.getState() == RefreshState.Loading
refreshLayout.getState() == RefreshState.Refreshing
refreshLayout.getState().isDragging
refreshLayout.getState().isFinishing
refreshLayout.getState().isHeader
refreshLayout.getState().isFooter
refreshLayout.getState().isOpening
```
--------------------------------
### Control Animation Start and Stop
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_custom.md
Manages the animation of the progress drawable. The `onStartAnimator` method is called when the refresh animation begins, and `onFinish` is called upon completion, updating the header text and stopping the animation.
```Java
public class ClassicsHeader extends LinearLayout implements RefreshHeader {
@Override
public void onStartAnimator(RefreshLayout layout, int headHeight, int maxDragHeight) {
mProgressDrawable.start();//开始动画
}
@Override
public int onFinish(RefreshLayout layout, boolean success) {
mProgressDrawable.stop();//停止动画
if (success){
mHeaderText.setText("刷新完成");
} else {
mHeaderText.setText("刷新失败");
}
return 500;//延迟500毫秒之后再弹回
}
}
```
--------------------------------
### Set Default Refresh Header Creator in Java
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
This Java code snippet demonstrates how to set a custom default refresh header creator for SmartRefreshLayout. It configures a MaterialHeader with specific color schemes and disables header translation content.
```java
SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
@Override
public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
//开始设置全局的基本参数(这里设置的属性只跟下面的MaterialHeader绑定,其他Header不会生效,能覆盖DefaultRefreshInitializer的属性和Xml设置的属性)
layout.setEnableHeaderTranslationContent(false);
return new MaterialHeader(context).setColorSchemeResources(R.color.colorRed,R.color.colorGreen,R.color.colorBlue);
}
});
```
--------------------------------
### Set Global Default SmartRefreshLayout Configuration
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_property.md
This snippet demonstrates how to set global default configurations for SmartRefreshLayout within an Android Application class. It uses `setDefaultRefreshInitializer` to apply default settings like rebound duration, interpolator, footer height, content disabling during loading, and primary colors, which can be overridden by individual view settings.
```java
public class App extends Application {
static {//使用static代码段可以防止内存泄漏
//设置全局默认配置(优先级最低,会被其他设置覆盖)
SmartRefreshLayout.setDefaultRefreshInitializer(new DefaultRefreshInitializer() {
@Override
public void initialize(@NonNull Context context, @NonNull RefreshLayout layout) {
//开始设置全局的基本参数(可以被下面的DefaultRefreshHeaderCreator覆盖)
layout.setReboundDuration(1000);
layout.setReboundInterpolator(new DropBounceInterpolator());
layout.setFooterHeight(100);
layout.setDisableContentWhenLoading(false);
layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);
}
});
//全局设置默认的 Header
```
--------------------------------
### Basic SmartRefreshLayout Initialization (Kotlin)
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/README_EN.md
This snippet shows the equivalent basic initialization of SmartRefreshLayout using Kotlin. It highlights the Kotlin syntax for accessing views and setting the refresh header and footer components, enabling essential pull-to-refresh and load-more functionalities.
```Kotlin
val refreshLayout = findViewById(R.id.refreshLayout)
refreshLayout.refreshHeader = ClassicsHeader(this)
refreshLayout.refreshFooter = ClassicsFooter(this)
refreshLayout.setEnableRefresh(true)
refreshLayout.setEnableLoadMore(true)
```
--------------------------------
### Initialize ClassicsHeader Component
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_custom.md
Initializes the ClassicsHeader by setting up member variables for text, arrow, and progress views, and adding them to the layout. It requires a Context object for initialization.
```Java
public class ClassicsHeader extends LinearLayout implements RefreshHeader {
private TextView mHeaderText;//标题文本
private PathsView mArrowView;//下拉箭头
private ImageView mProgressView;//刷新动画视图
private ProgressDrawable mProgressDrawable;//刷新动画
public ClassicsHeader(Context context) {
super(context);
setGravity(Gravity.CENTER_HORIZONTAL);
mHeaderText = new TextView(context);
mProgressDrawable = new ProgressDrawable();
mArrowView = new PathsView(context);
mProgressView = new ImageView(context);
mProgressView.setImageDrawable(mProgressDrawable);
addView(mProgressView);
addView(mArrowView, lpProgress);
addView(mHeaderText, lpHeaderText);
}
}
```
--------------------------------
### Package Layouts into Modules
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_update.md
Reorganizes the library by packaging different components into separate modules: `layout`, `two-level`, `header-classics`, `header-radar`, `header-falsify`, `footer-classics`, and `footer-ball`.
```Java
>分包:layout = kernel + two-level + header-classics + header-radar + header-falsify + footer-classics + footer-ball
```
--------------------------------
### Add srlStyle Theme Support
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_update.md
Introduces support for `srlStyle` themes, allowing for different visual styles for the refresh layout.
```Java
>添加:srlStyle 主题支持
```
--------------------------------
### Add SmartRefreshLayout Gradle Dependencies
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/README_EN.md
Includes core, various header, and footer dependencies for SmartRefreshLayout. Supports AndroidX and provides links to find the latest versions.
```Gradle
// Note: There will be no default Header and Footer after subcontracting. It needs to be added manually!
// To search lastest version by https://search.maven.org/search?q=g:io.github.scwang90
implementation 'io.github.scwang90:refresh-layout-kernel:3.0.0-alpha' //core
implementation 'io.github.scwang90:refresh-header-classics:3.0.0-alpha' //ClassicsHeader
implementation 'io.github.scwang90:refresh-header-radar:3.0.0-alpha' //BezierRadarHeader
implementation 'io.github.scwang90:refresh-header-falsify:3.0.0-alpha' //FalsifyHeader
implementation 'io.github.scwang90:refresh-header-material:3.0.0-alpha' //MaterialHeader
implementation 'io.github.scwang90:refresh-header-two-level:3.0.0-alpha' //TwoLevelHeader
implementation 'io.github.scwang90:refresh-footer-ball:3.0.0-alpha' //BallPulseFooter
implementation 'io.github.scwang90:refresh-footer-classics:3.0.0-alpha' //ClassicsFooter
```
--------------------------------
### Add DefaultRefreshInitializer for Global Initialization
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_update.md
Adds the `DefaultRefreshInitializer` class to provide global initialization settings for SmartRefreshLayout, allowing for consistent configuration across the application.
```Java
add: DefaultRefreshInitializer 全局初始化
```
--------------------------------
### SmartRefreshLayout: Load More Default and Smart Enable
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_update.md
Version 1.0.3 modifies the default behavior of `EnableLoadMore` from `true` to `false`. It also introduces a smart enabling feature for `EnableLoadMore` and `EnableNestedScrolling`, improving the library's adaptability and resource management.
```Java
/**
* Sets whether to enable load more functionality. Defaults to false.
* @param enable True to enable, false to disable.
*/
public void setEnableLoadMore(boolean enable) {
// Implementation details for enabling/disabling load more
}
/**
* Sets whether to enable nested scrolling. Defaults to false.
* @param enable True to enable, false to disable.
*/
public void setEnableNestedScrolling(boolean enable) {
// Implementation details for enabling/disabling nested scrolling
}
```
--------------------------------
### SmartRefreshLayout: New Headers Added
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_update.md
Version 1.0.0 introduces two new header types: `DeliveryHeader` and `DropboxHeader`, expanding the visual options for pull-to-refresh functionality.
```Java
// Introduction of DeliveryHeader and DropboxHeader
```
--------------------------------
### Add SmartRefreshLayout Dependencies
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/README.md
Integrate the SmartRefreshLayout library and its various header and footer components into your Android project by adding these dependencies to your app's build.gradle file. Ensure you have a compatible version of androidx.appcompat.
```Gradle
implementation 'androidx.appcompat:appcompat:1.0.0' //必须 1.0.0 以上
implementation 'io.github.scwang90:refresh-layout-kernel:3.0.0-alpha' //核心必须依赖
implementation 'io.github.scwang90:refresh-header-classics:3.0.0-alpha' //经典刷新头
implementation 'io.github.scwang90:refresh-header-radar:3.0.0-alpha' //雷达刷新头
implementation 'io.github.scwang90:refresh-header-falsify:3.0.0-alpha' //虚拟刷新头
implementation 'io.github.scwang90:refresh-header-material:3.0.0-alpha' //谷歌刷新头
implementation 'io.github.scwang90:refresh-header-two-level:3.0.0-alpha' //二级刷新头
implementation 'io.github.scwang90:refresh-footer-ball:3.0.0-alpha' //球脉冲加载
implementation 'io.github.scwang90:refresh-footer-classics:3.0.0-alpha' //经典加载
```
--------------------------------
### Enable AndroidX for SmartRefreshLayout
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/README_EN.md
Configuration for `gradle.properties` to enable AndroidX and Jetifier support, required for SmartRefreshLayout version 3.x and above.
```Gradle
android.useAndroidX=true
android.enableJetifier=true
```
--------------------------------
### Handle No More Data State
Source: https://github.com/scwang90/smartrefreshlayout/blob/main/art/md_faq.md
Illustrates how to manage the 'no more data' state after loading more. It shows how to call `finishLoadMoreWidthNoMoreData()` when there's no more data from the server and how to handle loading failures with `finishLoadMore(false)`.
```Java
//加载结束之后的逻辑
if (/*加载更多成功*/) {
if (/*服务器还有更多数据*/){
refreshlayout.finishLoadMore();
} else {
refreshlayout.finishLoadMoreWidthNoMoreData();//显示全部加载完成,并不再触发加载更事件
}
} else {
refreshlayout.finishLoadMore(false);//表示加载失败
}
//刷新结束之后
if (/*刷新成功*/) {
refreshlayout.finishRefresh();
refreshlayout.setNoMoreData(/*服务器不再有更多数据*/)//复原状态
} else {
refreshlayout.finishRefresh(false);//表示刷新失败(不会更新时间)
}
```