From 6f34472ea905ab26240539fbe04c3f3e2f8ce5ba Mon Sep 17 00:00:00 2001 From: LUX-Timber Date: Fri, 19 Apr 2024 16:36:00 +0800 Subject: [PATCH] doc:Updated the documentation and added kotlin examples --- README.md | 149 +++++++++++++++++++++++++++++++++++++-------------- README_EN.md | 127 +++++++++++++++++++++++++++++-------------- 2 files changed, 196 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index 0f463444..e6df58f3 100644 --- a/README.md +++ b/README.md @@ -21,43 +21,45 @@ IOS版本:[链接](https://github.com/scwang90/SmartRefreshControl) ## 国内加速 -github 由于你懂的原因,下载速度缓慢,图片也无法查看,可以跳转 [国内镜像](https://gitee.com/scwang90/SmartRefreshLayout) - -## 特点功能: - - - 支持多点触摸 - - 支持淘宝二楼和二级刷新 - - 支持嵌套多层的视图结构 Layout (LinearLayout,FrameLayout...) - - 支持所有的 View(AbsListView、RecyclerView、WebView....View) - - 支持自定义并且已经集成了很多炫酷的 Header 和 Footer. - - 支持和 ListView 的无缝同步滚动 和 CoordinatorLayout 的嵌套滚动 . - - 支持自动刷新、自动上拉加载(自动检测列表惯性滚动到底部,而不用手动上拉). - - 支持自定义回弹动画的插值器,实现各种炫酷的动画效果. - - 支持设置主题来适配任何场景的 App,不会出现炫酷但很尴尬的情况. - - 支持设多种滑动方式:平移、拉伸、背后固定、顶层固定、全屏 - - 支持所有可滚动视图的越界回弹 - - 支持 Header 和 Footer 交换混用 - - 支持 AndroidX - - 支持[横向刷新](https://github.com/scwang90/SmartRefreshHorizontal) - - 支持[IOS](https://github.com/scwang90/SmartRefreshControl) +github 由于你懂的原因,下载速度缓慢,图片也无法查看,可以跳转 [国内镜像](https://gitee.com/scwang90/SmartRefreshLayout) + +## 特点功能 + +- 支持多点触摸 +- 支持淘宝二楼和二级刷新 +- 支持嵌套多层的视图结构 Layout (LinearLayout,FrameLayout...) +- 支持所有的 View(AbsListView、RecyclerView、WebView....View) +- 支持自定义并且已经集成了很多炫酷的 Header 和 Footer. +- 支持和 ListView 的无缝同步滚动 和 CoordinatorLayout 的嵌套滚动 . +- 支持自动刷新、自动上拉加载(自动检测列表惯性滚动到底部,而不用手动上拉). +- 支持自定义回弹动画的插值器,实现各种炫酷的动画效果. +- 支持设置主题来适配任何场景的 App,不会出现炫酷但很尴尬的情况. +- 支持设多种滑动方式:平移、拉伸、背后固定、顶层固定、全屏 +- 支持所有可滚动视图的越界回弹 +- 支持 Header 和 Footer 交换混用 +- 支持 AndroidX +- 支持[横向刷新](https://github.com/scwang90/SmartRefreshHorizontal) +- 支持[IOS](https://github.com/scwang90/SmartRefreshControl) ## 传送门 - - [属性文档](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_property.md) - - [常见问题](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_faq.md) - - [智能之处](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_smart.md) - - [更新日志](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_update.md) - - [博客文章](https://segmentfault.com/a/1190000010066071) - - [源码下载](https://github.com/scwang90/SmartRefreshLayout/releases) - - [多点触摸](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_multitouch.md) - - [自定义Header](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_custom.md) +- [属性文档](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_property.md) +- [常见问题](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_faq.md) +- [智能之处](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_smart.md) +- [更新日志](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_update.md) +- [博客文章](https://segmentfault.com/a/1190000010066071) +- [源码下载](https://github.com/scwang90/SmartRefreshLayout/releases) +- [多点触摸](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_multitouch.md) +- [自定义Header](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_custom.md) ## Demo + [下载 APK-Demo](https://github.com/scwang90/SmartRefreshLayout/blob/master/art/app-debug.apk) ![](https://scwang90.github.io/assets/refresh-layout/png_apk_rqcode.png) #### 项目演示 + |个人首页|微博列表| |:---:|:---:| |![](https://scwang90.github.io/assets/refresh-layout/gif_practive_weibo_new.gif)|![](https://scwang90.github.io/assets/refresh-layout/gif_practive_feedlist_new.gif)| @@ -67,6 +69,7 @@ github 由于你懂的原因,下载速度缓慢,图片也无法查看,可 |![](https://scwang90.github.io/assets/refresh-layout/gif_practive_repast_new.gif)|![](https://scwang90.github.io/assets/refresh-layout/gif_practive_profile.gif)| #### 样式演示 Style + |Delivery|DropBox| |:---:|:---:| |![](https://scwang90.github.io/assets/refresh-layout/gif_Delivery.gif)|![](https://scwang90.github.io/assets/refresh-layout/gif_Dropbox.gif)| @@ -104,22 +107,21 @@ github 由于你懂的原因,下载速度缓慢,图片也无法查看,可 |![](https://scwang90.github.io/assets/refresh-layout/gif_StoreHouse.gif)|![](https://scwang90.github.io/assets/refresh-layout/gif_WaterDrop.gif)| |[CRefreshLayout](https://github.com/cloay/CRefreshLayout)|[WaterDrop](https://github.com/THEONE10211024/WaterDropListView) - 看到这么多炫酷的Header,是不是觉得很棒?这时你或许会担心这么多的Header集成在一起,但是平时只会用到一个,是不是要引入很多无用的代码和资源? V2.x 版本已经把依赖库拆分成8个包啦,用到的时候自行引用就可以啦! - - refresh-layout-kernel 核心必须依赖 - - refresh-header-classics 经典刷新头 - - refresh-header-radar 雷达刷新头 - - refresh-header-falsify 虚拟刷新头 - - refresh-header-material 谷歌刷新头 - - refresh-header-two-level 二级刷新头 - - refresh-footer-ball 球脉冲加载 - - refresh-footer-classics 经典加载 +- refresh-layout-kernel 核心必须依赖 +- refresh-header-classics 经典刷新头 +- refresh-header-radar 雷达刷新头 +- refresh-header-falsify 虚拟刷新头 +- refresh-header-material 谷歌刷新头 +- refresh-header-two-level 二级刷新头 +- refresh-footer-ball 球脉冲加载 +- refresh-footer-classics 经典加载 ## 简单用例 -#### 1.在 build.gradle 中添加依赖 +#### 1.在 build.gradle 中添加依赖 ```gradle implementation 'androidx.appcompat:appcompat:1.0.0' //必须 1.0.0 以上 @@ -145,6 +147,7 @@ android.enableJetifier=true ``` #### 2.在XML布局文件中添加 SmartRefreshLayout + ```xml + refreshlayout.finishRefresh(2000/*,false*/) // 传入false表示刷新失败 +} +refreshLayout.setOnLoadMoreListener { + refreshlayout -> + refreshlayout.finishLoadMore(2000/*,false*/) // 传入false表示加载失败 +} +``` + ## 使用指定的 Header 和 Footer #### 1.方法一 全局设置 + +##### Java + ```java public class App extends Application { //static 代码段可以防止内存泄露 @@ -212,10 +237,33 @@ public class App extends Application { } ``` -注意:方法一 设置的Header和Footer的优先级是最低的,如果同时还使用了方法二、三,将会被其它方法取代 +##### Kotlin + +```kotlin +class App : Application() { + init { + // 设置全局的Header构建器 + SmartRefreshLayout.setDefaultRefreshHeaderCreator(object : DefaultRefreshHeaderCreator() { + override fun createRefreshHeader(context: Context, layout: RefreshLayout): RefreshHeader { + layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white) // 全局设置主题颜色 + return ClassicsHeader(context) //.setTimeFormat(DynamicTimeFormat("更新于 %s"));//指定为经典Header,默认是 贝塞尔雷达Header + } + }) + // 设置全局的Footer构建器 + SmartRefreshLayout.setDefaultRefreshFooterCreator(object : DefaultRefreshFooterCreator() { + override fun createRefreshFooter(context: Context, layout: RefreshLayout): RefreshFooter { + // 指定为经典Footer,默认是 BallPulseFooter + return ClassicsFooter(context).setDrawableSize(20) + } + }) + } +} +``` +注意:方法一 设置的Header和Footer的优先级是最低的,如果同时还使用了方法二、三,将会被其它方法取代 #### 2.方法二 XML布局文件指定 + ```xml #### 温馨提示 + 加入群的答案在本文档中可以找到~ ## 其他作品 + [MultiWaveHeader](https://github.com/scwang90/MultiWaveHeader) [SmartRefreshHorizontal](https://github.com/scwang90/SmartRefreshHorizontal) [诗和远方](http://android.myapp.com/myapp/detail.htm?apkName=com.poetry.kernel) ## 感谢 + [SwipeRefreshLayout](https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html) [Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh) [TwinklingRefreshLayout](https://github.com/lcodecorex/TwinklingRefreshLayout) diff --git a/README_EN.md b/README_EN.md index bf4878e3..ffd1ffc6 100644 --- a/README_EN.md +++ b/README_EN.md @@ -16,35 +16,38 @@ SmartRefreshControl:[Link](https://github.com/scwang90/SmartRefreshControl) ## Features - - Support multi-touch. - - Support multi-layered nested view structures. - - Support all the Views(AbsListView、RecyclerView、WebView....View) - - Support customizing Headers and Footers, and has integrated a lot of cool Headers and Footers. - - Support synchronous scrolling with ListView and NestedScrolling with CoordinatorLayout. - - Support automatically refresh, automatically pull-up loading (automatically detect list inertance and scroll to the bottom without having to manually pull). - - Support customizing rebound animation interpolator, to achieve a variety of cool animation effects. - - Support setting a theme to fit any scene of App, it won't appear a cool but very awkward situation. - - Support setting a variety of transformations (Translation, stretching, behind fixed, top fixed, full screen view) for Headers and Footers. - - Support rewrite and extension, internal implementation without private methods and fields. - - Support automatically cross-border rebound for all rolling Views (ListView、RecyclerView、ScrollView、WebView...View). - - Support the interchange of Header and Footer - - Support AndroidX - - Support [HorizontalRefresh](https://github.com/scwang90/SmartRefreshHorizontal) - +- Support multi-touch. +- Support multi-layered nested view structures. +- Support all the Views(AbsListView、RecyclerView、WebView....View) +- Support customizing Headers and Footers, and has integrated a lot of cool Headers and Footers. +- Support synchronous scrolling with ListView and NestedScrolling with CoordinatorLayout. +- Support automatically refresh, automatically pull-up loading (automatically detect list inertance and scroll to the bottom without having to manually pull). +- Support customizing rebound animation interpolator, to achieve a variety of cool animation effects. +- Support setting a theme to fit any scene of App, it won't appear a cool but very awkward situation. +- Support setting a variety of transformations (Translation, stretching, behind fixed, top fixed, full screen view) for Headers and Footers. +- Support rewrite and extension, internal implementation without private methods and fields. +- Support automatically cross-border rebound for all rolling Views (ListView、RecyclerView、ScrollView、WebView...View). +- Support the interchange of Header and Footer +- Support AndroidX +- Support [HorizontalRefresh](https://github.com/scwang90/SmartRefreshHorizontal) + ## Gateway - - [Smart place](art/md_smart.md) - - [Update log](art/md_update.md) - - [Attribute method](art/md_property.md) - - [Blog posts](https://segmentfault.com/a/1190000010066071) - - [Download the source code](https://github.com/scwang90/SmartRefreshLayout/releases) - - [Multi-touch](art/md_multitouch.md) +- [Smart place](art/md_smart.md) +- [Update log](art/md_update.md) +- [Attribute method](art/md_property.md) +- [Blog posts](https://segmentfault.com/a/1190000010066071) +- [Download the source code](https://github.com/scwang90/SmartRefreshLayout/releases) +- [Multi-touch](art/md_multitouch.md) + ## Demo + [Download APK-Demo](art/app-debug.apk) ![](art/png_apk_rqcode.png) #### Practical + |Weibo|FeedList| |:---:|:---:| |![](art/gif_practive_weibo.gif)|![](art/gif_practive_feedlist.gif)| @@ -92,21 +95,21 @@ The two above headers are implemented by myself, The following headers are colle |Demo|![](art/gif_StoreHouse.gif)|![](art/gif_WaterDrop.gif)| |From|[Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh)|[WaterDrop](https://github.com/THEONE10211024/WaterDropListView) - -See so many cool headers, is not it feel great? At this point you may be worried that so many headers together, but usually only use one, is not to introduce a lot of useless code and resources? +See so many cool headers, is not it feel great? At this point you may be worried that so many headers together, but usually only use one, is not to introduce a lot of useless code and resources? Please rest assured that I have divided it into eight packages, when used to reference their own it! - - refresh-layout-kernel core - - refresh-header-classics ClassicsHeader - - refresh-header-radar BezierRadarHeader - - refresh-header-falsify FalsifyHeader - - refresh-header-material MaterialHeader - - refresh-header-two-level TwoLevelHeader - - refresh-footer-ball BallPulseFooter - - refresh-footer-classics ClassicsFooter +- refresh-layout-kernel core +- refresh-header-classics ClassicsHeader +- refresh-header-radar BezierRadarHeader +- refresh-header-falsify FalsifyHeader +- refresh-header-material MaterialHeader +- refresh-header-two-level TwoLevelHeader +- refresh-footer-ball BallPulseFooter +- refresh-footer-classics ClassicsFooter ## Usage -#### 1.Add a gradle dependency. + +#### 1.Add a gradle dependency V 2.x changed the package name relative to 1.x, such as `com.scwang.smartrefresh` to `com.scwang.smart.refresh`. It is suggested that in the new project, if the old project is upgraded, @@ -143,7 +146,8 @@ android.useAndroidX=true android.enableJetifier=true ``` -#### 2.Add SmartRefreshLayout in the layout xml. +#### 2.Add SmartRefreshLayout in the layout xml + ```xml ``` -#### 3.Coding in the Activity or Fragment. +#### 3.Coding in the Activity or Fragment + +#### Java + ```java RefreshLayout refreshLayout = (RefreshLayout)findViewById(R.id.refreshLayout); refreshLayout.setRefreshHeader(new ClassicsHeader(this)); @@ -173,20 +180,38 @@ refreshLayout.setRefreshFooter(new ClassicsFooter(this)); refreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(RefreshLayout refreshlayout) { - refreshlayout.finishRefresh(2000/*,false*/);//传入false表示刷新失败 - } + refreshlayout.finishRefresh(2000/*,false*/); }); refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() { @Override public void onLoadMore(RefreshLayout refreshlayout) { - refreshlayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败 + refreshlayout.finishLoadMore(2000/*,false*/); } }); ``` +#### Kotlin + +```kotlin +val refreshLayout: RefreshLayout = findViewById(R.id.refreshLayout) +refreshLayout.setRefreshHeader(ClassicsHeader(this)) +refreshLayout.setRefreshFooter(ClassicsFooter(this)) +refreshLayout.setOnRefreshListener { + refreshlayout -> + refreshlayout.finishRefresh(2000/*,false*/) +} +refreshLayout.setOnLoadMoreListener { + refreshlayout -> + refreshlayout.finishLoadMore(2000/*,false*/) +} +``` + ## Use the specified Header and Footer #### 1.Global settings + +##### Java + ```java public class App extends Application { public void onCreate() { @@ -207,10 +232,30 @@ public class App extends Application { } ``` -Note: this method is the lowest priority. +##### Kotlin + +```kotlin +class App : Application() { + init { + SmartRefreshLayout.setDefaultRefreshHeaderCreator(object : DefaultRefreshHeaderCreator() { + override fun createRefreshHeader(context: Context, layout: RefreshLayout): RefreshHeader { + layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white) + return ClassicsHeader(context) + } + }) + SmartRefreshLayout.setDefaultRefreshFooterCreator(object : DefaultRefreshFooterCreator() { + override fun createRefreshFooter(context: Context, layout: RefreshLayout): RefreshFooter { + return ClassicsFooter(context).setDrawableSize(20) + } + }) + } +} +``` +Note: this method is the lowest priority. #### 2.Specified in the XML layout file + ```xml ## Thanks + [SwipeRefreshLayout](https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html) [Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh) [TwinklingRefreshLayout](https://github.com/lcodecorex/TwinklingRefreshLayout) [BeautifulRefreshLayout](https://github.com/android-cjj/BeautifulRefreshLayout) ## Other Works + [MultiWaveHeader](https://github.com/scwang90/MultiWaveHeader) [SmartRefreshHorizontal](https://github.com/scwang90/SmartRefreshHorizontal)