使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Swiperefreshlayout
实现下拉刷新的界面模式。
声明依赖项
要添加 SwipeRefreshLayout 的依赖项,您必须将 Google Maven 代码库添加到项目中。如需了解详情,请参阅 Google 的 Maven 代码库。
在应用或模块的 build.gradle
文件中添加所需工件的依赖项:
Groovy
dependencies {
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
}
Kotlin
dependencies {
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
}
如需详细了解依赖项,请参阅添加 build 依赖项。
反馈
您的反馈将帮助我们改进 Jetpack。如果您发现了新问题,或对此库有任何改进建议,请告诉我们。创建新问题前,请先查看此库中的现有问题。您可以点击星标按钮,为现有问题投票。
创建新问题
如需了解详情,请参阅问题跟踪器文档。
版本 1.2.0
版本 1.2.0-beta01
2025 年 2 月 12 日
发布了 androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-beta01
。版本 1.2.0-beta01 包含这些提交内容。
API 变更
bug 修复
版本 1.2.0-alpha01
2020 年 7 月 22 日
发布了 androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01
。版本 1.2.0-alpha01 中包含这些提交内容。
问题修复
requestDisallowInterceptTouchEvent(boolean)
现在遵照请求进行处理,像任何其他 ViewGroup 一样。您可以通过 setLegacyRequestDisallowInterceptTouchEventEnabled
停用新行为,但强烈建议不要这样做。(I968da、b/141855018)
版本 1.1.0
版本 1.1.0
2020 年 6 月 24 日
发布了 androidx.swiperefreshlayout:swiperefreshlayout:1.1.0
。版本 1.1.0 中包含这些提交内容。
自 1.0.0 以来的重要变更
SwipeRefreshLayout
现在会实现 NestedScrollingChild3
和 NestedScrollingParent3
。
版本 1.1.0-rc01
2020 年 4 月 15 日
发布了 androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-rc01
,该版本与 1.1.0-beta01
相比没有变化。版本 1.1.0-rc01 中包含这些提交内容。
版本 1.1.0-beta01
2020 年 3 月 4 日
发布了 androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-beta01
,该版本与 1.1.0-alpha03
相比没有变化。版本 1.1.0-beta01 中包含这些提交内容。
版本 1.1.0-alpha03
2019 年 10 月 9 日
发布了 androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha03
。版本 1.1.0-alpha03 中包含这些提交内容。
新功能
- 有一个新的样式属性
R.styleable.SwipeRefreshLayout_swipeRefreshLayoutProgressSpinnerBackgroundColor
来设置进度指示器的背景颜色。(aosp/931124)
API 变更
requestDisallowInterceptTouchEvent(boolean)
现在始终传递至其父级。虽然强烈建议不要使用,但是可通过 setLegacyRequestDisallowInterceptTouchEventEnabled
停用新行为。(aosp/1108540)
问题修复
版本 1.1.0-alpha02
2019 年 7 月 2 日
发布了 androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02
。点击此处可查看此版本中包含的提交内容。
问题修复
- 可保存和恢复 SwipeRefreshLayout 的刷新状态
- 修复了将 SwipeRefreshLayout 嵌入到 RecyclerView 中时出现的易用性错误
版本 1.1.0-alpha01
2018 年 12 月 3 日
API 变更
- aosp/737631:
SwipeRefreshLayout
现在会实现 NestedScrollingChild3
和 NestedScrollingParent3
,从而使嵌套滚动 3 个父级和子级能够通过 SwipeRefreshLayout
传递所使用的嵌套滚动距离信息。如果开发者代码当前替换 SwipeRefreshLayout.onNestedScroll(View, int, int, int, int, int)
,则它有可能不会再被调用,因此应该改为替换 SwipeRefreshLayout.onNestedScroll(View, int, int, int, int, int, int[])
。同样,系统也可能不会再调用 SwipeRefreshLayout.dispatchNestedScroll(int, int, int, int, int[], int)
,因此应改为替换 SwipeRefreshLayout.dispatchNestedScroll(int, int, int, int, int[], int, int[])
。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Swiperefreshlayout\n==================\n\n[Code Sample](https://github.com/android/views-widgets-samples) \nAPI Reference \n[androidx.swiperefreshlayout.widget](/reference/kotlin/androidx/swiperefreshlayout/widget/package-summary) \nImplement the swipe-to-refresh UI pattern. \n\n| Latest Update | Stable Release | Release Candidate | Beta Release | Alpha Release |\n|-------------------|--------------------------------------------------------------|-------------------|----------------------------------------------------------------------------|---------------|\n| February 12, 2025 | [1.1.0](/jetpack/androidx/releases/swiperefreshlayout#1.1.0) | - | [1.2.0-beta01](/jetpack/androidx/releases/swiperefreshlayout#1.2.0-beta01) | - |\n\nDeclaring dependencies\n----------------------\n\nTo add a dependency on SwipeRefreshLayout, you must add the Google Maven repository to your\nproject. Read [Google's Maven repository](/studio/build/dependencies#google-maven)\nfor more information.\n\nAdd the dependencies for the artifacts you need in the `build.gradle` file for\nyour app or module: \n\n### Groovy\n\n```groovy\ndependencies {\n implementation \"androidx.swiperefreshlayout:swiperefreshlayout:1.1.0\"\n}\n```\n\n### Kotlin\n\n```kotlin\ndependencies {\n implementation(\"androidx.swiperefreshlayout:swiperefreshlayout:1.1.0\")\n}\n```\n\nFor more information about dependencies, see [Add build dependencies](/studio/build/dependencies).\n\nFeedback\n--------\n\nYour feedback helps make Jetpack better. Let us know if you discover new issues or have\nideas for improving this library. Please take a look at the\n[existing issues](https://issuetracker.google.com/issues?q=componentid:460836%20status:open)\nin this library before you create a new one. You can add your vote to an existing issue by\nclicking the star button.\n\n[Create a new issue](https://issuetracker.google.com/issues/new?component=460836&template=1422576)\n\nSee the [Issue Tracker documentation](https://developers.google.com/issue-tracker)\nfor more information.\n\nVersion 1.2.0\n-------------\n\n### Version 1.2.0-beta01\n\nFebruary 12, 2025\n\n`androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-beta01` is released. Version 1.2.0-beta01 contains [these commits](https://android.googlesource.com/platform/frameworks/support/+log/9f60cc700129e30cee9df020005c317fb39d32ec..7344269b2d862d014a647efafcd7735f0d53f1da/swiperefreshlayout/swiperefreshlayout).\n\n**API Changes**\n\n- Specified nullability of `SwipeRefreshLayout` method parameters and return types ([I006d1](https://android-review.googlesource.com/#/q/I006d15100662ca77db65dd0cf4735c65cee84dfd), [b/236497776](https://issuetracker.google.com/issues/236497776))\n\n**Bug Fixes**\n\n- This library now uses [JSpecify nullness annotations](https://jspecify.dev/), which are type-use. Kotlin developers should use the following compiler argument to enforce correct usage: `-Xjspecify-annotations=strict` (this is the default starting with version 2.1.0 of the Kotlin compiler). ([Iaf490](https://android-review.googlesource.com/#/q/Iaf49080833b450a7dbba982367bfd863a2ead6ad), [b/326456246](https://issuetracker.google.com/issues/326456246))\n\n### Version 1.2.0-alpha01\n\nJuly 22, 2020\n\n`androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01` is released. [Version 1.2.0-alpha01 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/6b97b146b743340c9d9b6fa54e735404374f2a5f..9f60cc700129e30cee9df020005c317fb39d32ec/swiperefreshlayout/swiperefreshlayout)\n\n**Bug Fixes**\n\n- `requestDisallowInterceptTouchEvent(boolean)` now honors the request like any other ViewGroup. While strongly discouraged, new behavior can be disabled with `setLegacyRequestDisallowInterceptTouchEventEnabled`. ([I968da](https://android-review.googlesource.com/#/q/I968da769d8400caf6f52c8a12595ee19fb4c0773), [b/141855018](https://issuetracker.google.com/issues/141855018))\n\nVersion 1.1.0\n-------------\n\n### Version 1.1.0\n\nJune 24, 2020\n\n`androidx.swiperefreshlayout:swiperefreshlayout:1.1.0` is released. [Version 1.1.0 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/6563b7854e79a3f7182efe27ee726867a091b603..6b97b146b743340c9d9b6fa54e735404374f2a5f/swiperefreshlayout/swiperefreshlayout)\n\n**Major changes since 1.0.0**\n\n- `SwipeRefreshLayout` now implements `NestedScrollingChild3` and `NestedScrollingParent3`.\n\n### Version 1.1.0-rc01\n\nApril 15, 2020\n\n`androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-rc01` is released with no changes since `1.1.0-beta01`. [Version 1.1.0-rc01 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/666ae665acfcfa2a20eccc18e4494808169742f4..6563b7854e79a3f7182efe27ee726867a091b603/swiperefreshlayout/swiperefreshlayout)\n\n### Version 1.1.0-beta01\n\nMarch 4, 2020\n\n`androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-beta01` is released with no changes since `1.1.0-alpha03`. [Version 1.1.0-beta01 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/f14ad350142290622d1645e1d0e280cbe8ca4c2f..666ae665acfcfa2a20eccc18e4494808169742f4/swiperefreshlayout/swiperefreshlayout)\n\n### Version 1.1.0-alpha03\n\nOctober 9, 2019\n\n`androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha03` is released. [Version 1.1.0-alpha03 contains these commits](https://android.googlesource.com/platform/frameworks/support/+log/9a7b3cb32a2c7adac9b7af4bc2f996f1eb79fc12..f14ad350142290622d1645e1d0e280cbe8ca4c2f/swiperefreshlayout).\n\n**New features**\n\n- We have a new style attribute `R.styleable.SwipeRefreshLayout_swipeRefreshLayoutProgressSpinnerBackgroundColor`to set the background color of the progress indicator. ([aosp/931124](https://android-review.googlesource.com/931124))\n\n**API changes**\n\n- `requestDisallowInterceptTouchEvent(boolean)` now always propagates up to its parents. While strongly discouraged, new behavior can be disabled with `setLegacyRequestDisallowInterceptTouchEventEnabled`. ([aosp/1108540](https://android-review.googlesource.com/1108540))\n\n**Bug fixes**\n\n- Fixed issue with nested scrolling where SwipeRefreshLayout has a scrollable parent (e.g. [ViewPager2](/jetpack/androidx/releases/viewpager2)) and a scrollable child. ([b/138314213](https://issuetracker.google.com/issues/138314213))\n\n### Version 1.1.0-alpha02\n\nJuly 2, 2019\n\n`androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02` is released. The commits included in this version can be found [here](https://android.googlesource.com/platform/frameworks/support/+log/d9ca300b3f70db75744a6d743f85e3784287434a..9a7b3cb32a2c7adac9b7af4bc2f996f1eb79fc12/swiperefreshlayout).\n| **Note:** This version is dependent on the Java 8 programming language. Please read [Use Java 8 language features](/studio/write/java8-support) to learn how to use it in your project.\n\n**Bug fixes**\n\n- Implemented saving and restoring of the refreshing state of SwipeRefreshLayout\n- Fixed usability bug when SwipeRefreshLayout is embedded in a RecyclerView\n\n### Version 1.1.0-alpha01\n\nDecember 3, 2018\n\n**API changes**\n\n- [aosp/737631](): `SwipeRefreshLayout` now implements `NestedScrollingChild3` and `NestedScrollingParent3`, enabling nested scrolling 3 parents and children to pass consumed nested scrolling distance information through `SwipeRefreshLayout`. If developer code currently overrides `SwipeRefreshLayout.onNestedScroll(View, int, int, int, int, int)`, it will likely no longer be called and `SwipeRefreshLayout.onNestedScroll(View, int, int, int, int, int, int[])` should be overridden instead. Likewise, `SwipeRefreshLayout.dispatchNestedScroll(int, int, int, int, int[], int)` will likely no longer be called and `SwipeRefreshLayout.dispatchNestedScroll(int, int, int, int, int[], int, int[])` should be overridden instead."]]