{"id":13396018,"url":"https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh","last_synced_at":"2025-03-13T22:31:35.134Z","repository":{"id":23211284,"uuid":"26568234","full_name":"liaohuqiu/android-Ultra-Pull-To-Refresh","owner":"liaohuqiu","description":"Ultra Pull to Refresh for Android. Support all the views.","archived":false,"fork":false,"pushed_at":"2023-05-28T15:12:24.000Z","size":3474,"stargazers_count":9582,"open_issues_count":172,"forks_count":2653,"subscribers_count":439,"default_branch":"master","last_synced_at":"2024-10-29T15:03:09.657Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/liaohuqiu.png","metadata":{"files":{"readme":"README-cn.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2014-11-13T03:13:10.000Z","updated_at":"2024-10-24T07:26:27.000Z","dependencies_parsed_at":"2024-01-31T23:03:35.672Z","dependency_job_id":"d147cb42-86de-40b7-bee8-bb48be098ac6","html_url":"https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liaohuqiu%2Fandroid-Ultra-Pull-To-Refresh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liaohuqiu%2Fandroid-Ultra-Pull-To-Refresh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liaohuqiu%2Fandroid-Ultra-Pull-To-Refresh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liaohuqiu%2Fandroid-Ultra-Pull-To-Refresh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liaohuqiu","download_url":"https://codeload.github.com/liaohuqiu/android-Ultra-Pull-To-Refresh/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243125547,"owners_count":20240276,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T18:00:37.807Z","updated_at":"2025-03-13T22:31:35.112Z","avatar_url":"https://github.com/liaohuqiu.png","language":"Java","funding_links":[],"categories":["Index `(light-weight pages)`","Java","下拉刷新","Index","第一部分 个性化控件(View)"],"sub_categories":[],"readme":"###### 欢迎关注我\n\nGitHub: https://github.com/liaohuqiu\n\n微博: http://weibo.com/liaohuqiu\n\n知乎: http://www.zhihu.com/people/liao-hu-qiu\n\n---\n\n# Ultra Pull To Refresh\n\n这是现在已经停止维护的下拉刷新项目的替代方案。继承于ViewGroup可以包含任何View。功能比SwipeRefreshLayout强大。\n\n使用起来非常简单。良好的设计，如果你想定制自己的UI样式，非常简单，就像给ListView加一个Header View那么简单。\n\n支持 `API LEVEL \u003e= 8`。\n\n[APK下载](https://raw.githubusercontent.com/liaohuqiu/android-Ultra-Pull-To-Refresh/master/ptr-demo.apk)\n\n#### 下拉刷新 + 加载更多？\n\n本类库是单纯的下拉刷新。如果你需要用到`加载更多`，看这个项目: https://github.com/liaohuqiu/android-cube-app\n\n#### 使用eclipse的同学请注意, Intellij IDEA / Android Studio 请忽略\n\n**demo可以直接在eclipse中运行, 编译demo项目的同学看这里:  http://www.liaohuqiu.net/cn/posts/compile-ultra-ptr-in-eclipse/**\n\n* 先上两张StoreHouse风格的截图! 感谢 [CBStoreHouseRefreshControl](https://github.com/coolbeet/CBStoreHouseRefreshControl).\n    \u003cdiv class='row'\u003e\n        \u003cimg src='http://srain-github.qiniudn.com/ultra-ptr/store-house-string-array.gif' width=\"300px\" style='border: #f1f1f1 solid 1px'/\u003e\n        \u003cimg src='http://srain-github.qiniudn.com/ultra-ptr/store-house-string.gif' width=\"300px\" style='border: #f1f1f1 solid 1px'/\u003e\n    \u003c/div\u003e\n\n* 5.0 Material 风格 2014-12-09 新增。**阴影效果，gif图看起来有些失真，看demo吧！**\n    \u003cdiv class='row'\u003e\n        \u003cimg src='http://srain-github.qiniudn.com/ultra-ptr/material-style.gif' width=\"300px\"/\u003e\n    \u003c/div\u003e\n\n* **支持所有的View**: \n\n    ListView, GridView, ScrollView, FrameLayout, 甚至 TextView.\n    \u003cdiv\u003e\u003cimg src='http://srain-github.qiniudn.com/ultra-ptr/contains-all-of-views.gif' width=\"300px\" style='border: #f1f1f1 solid 1px'/\u003e\u003c/div\u003e\n\n* 支持各种下拉刷新交互.\n    * 下拉刷新(iOS风格)\n        \u003cdiv\u003e\u003cimg src='http://srain-github.qiniudn.com/ultra-ptr/pull-to-refresh.gif' width=\"300px\" style='border: #f1f1f1 solid 1px'/\u003e\u003c/div\u003e\n\n    * 释放刷新(经典风格)\n        \u003cdiv\u003e\u003cimg src='http://srain-github.qiniudn.com/ultra-ptr/release-to-refresh.gif' width=\"300px\" style='border: #f1f1f1 solid 1px'/\u003e\u003c/div\u003e\n\n    * 刷新时，头部保持(新浪微博)\n\n        \u003cimg src='http://srain-github.qiniudn.com/ultra-ptr/keep-header.gif' width=\"300px\"/\u003e\n\n    * 刷新时，头部不保持(微信朋友圈)\n\n        \u003cimg src='http://srain-github.qiniudn.com/ultra-ptr/hide-header.gif' width=\"300px\" sytle='border: #f1f1f1 solid 1px'/\u003e\n\n    * 自动刷新，进入界面时自动刷新\n\n        \u003cimg src='http://srain-github.qiniudn.com/ultra-ptr/auto-refresh.gif' width=\"300px\" sytle='border: #f1f1f1 solid 1px'/\u003e\u003c/div\u003e\n\n# 使用方式\n\n#### 中央库依赖\n\n项目已经发布到了Maven中央库，包括`aar`和`apklib`两种格式。在Maven或者Gradle下可如下直接引入:\n\n最新版版本号: `1.0.11`, 发布到了: https://oss.sonatype.org/content/repositories/snapshots\n\n在gradle中:\n\n```\nmaven {\n    url 'https://oss.sonatype.org/content/repositories/snapshots'\n}\n```\n\n稳定版: `1.0.11`, https://oss.sonatype.org/content/repositories/releases, in gradle:\n\n```\nmavenCentral()\n```\n\n`pom.xml` 文件中\n\n最新版:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ein.srain.cube\u003c/groupId\u003e\n    \u003cartifactId\u003eultra-ptr\u003c/artifactId\u003e\n    \u003ctype\u003eaar\u003c/type\u003e\n    \u003c!-- or apklib format, if you want --\u003e\n    \u003c!-- \u003ctype\u003eapklib\u003c/type\u003e --\u003e\n    \u003cversion\u003e1.0.11\u003c/version\u003e\n\u003c/dependency\u003e\n\n稳定版\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ein.srain.cube\u003c/groupId\u003e\n    \u003cartifactId\u003eultra-ptr\u003c/artifactId\u003e\n    \u003ctype\u003eaar\u003c/type\u003e\n    \u003c!-- or apklib format, if you want --\u003e\n    \u003c!-- \u003ctype\u003eapklib\u003c/type\u003e --\u003e\n    \u003cversion\u003e1.0.11\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\ngradle / Android Studio, 最新版\n\n```\ncompile 'in.srain.cube:ultra-ptr:1.0.11'\n```\n\ngradle / Android Studio, 稳定版\n\n```\ncompile 'in.srain.cube:ultra-ptr:1.0.11'\n```\n\n#### 配置\n\n有6个参数可配置:\n\n* 阻尼系数\n\n    默认: `1.7f`，越大，感觉下拉时越吃力。\n\n* 触发刷新时移动的位置比例\n\n    默认，`1.2f`，移动达到头部高度1.2倍时可触发刷新操作。\n\n* 回弹延时\n\n    默认 `200ms`，回弹到刷新高度所用时间\n\n* 头部回弹时间\n\n    默认`1000ms`\n\n* 刷新是保持头部\n\n    默认值 `true`.\n\n* 下拉刷新 / 释放刷新\n\n    默认为释放刷新\n\n##### xml中配置示例\n\n```xml\n\u003cin.srain.cube.views.ptr.PtrFrameLayout\n    android:id=\"@+id/store_house_ptr_frame\"\n    xmlns:cube_ptr=\"http://schemas.android.com/apk/res-auto\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n\n    cube_ptr:ptr_resistance=\"1.7\"\n    cube_ptr:ptr_ratio_of_header_height_to_refresh=\"1.2\"\n    cube_ptr:ptr_duration_to_close=\"300\"\n    cube_ptr:ptr_duration_to_close_header=\"2000\"\n    cube_ptr:ptr_keep_header_when_refresh=\"true\"\n    cube_ptr:ptr_pull_to_fresh=\"false\" \u003e\n\n    \u003cLinearLayout\n        android:id=\"@+id/store_house_ptr_image_content\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        android:background=\"@color/cube_mints_333333\"\n        android:clickable=\"true\"\n        android:padding=\"10dp\"\u003e\n\n        \u003cin.srain.cube.image.CubeImageView\n            android:id=\"@+id/store_house_ptr_image\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"match_parent\" /\u003e\n    \u003c/LinearLayout\u003e\n\n\u003c/in.srain.cube.views.ptr.PtrFrameLayout\u003e\n```\n\n### 也可以在java代码中配置\n\n```java\n// the following are default settings\nmPtrFrame.setResistance(1.7f);\nmPtrFrame.setRatioOfHeaderHeightToRefresh(1.2f);\nmPtrFrame.setDurationToClose(200);\nmPtrFrame.setDurationToCloseHeader(1000);\n// default is false\nmPtrFrame.setPullToRefresh(false);\n// default is true\nmPtrFrame.setKeepHeaderWhenRefresh(true);\n```\n\n### 其他配置\n\n*  刷新时，保持内容不动，仅头部下移, `setPinContent()`\n\n    `Material` 风格时，效果不错，其他风格的头部，效果不好。issue #29\n\n## StoreHouse 风格\n\n* 使用字符串, 支持A-Z, 0-7 以及 `-` `.`\n\n```java\n// header\nfinal StoreHouseHeader header = new StoreHouseHeader(getContext());\nheader.setPadding(0, LocalDisplay.dp2px(15), 0, 0);\n\n/**\n * using a string, support: A-Z 0-9 - .\n * you can add more letters by {@link in.srain.cube.views.ptr.header.StoreHousePath#addChar}\n */\nheader.initWithString('Alibaba');\n```\n\n* 使用资源文件中的路径信息\n\n```java\nheader.initWithStringArray(R.array.storehouse);\n```\n\n资源文件 `res/values/arrays.xml` 内容如下:\n\n```xml\n\u003cresources\u003e\n    \u003cstring-array name=\"storehouse\"\u003e\n        \u003citem\u003e0,35,12,42,\u003c/item\u003e\n        \u003citem\u003e12,42,24,35,\u003c/item\u003e\n        \u003citem\u003e24,35,12,28,\u003c/item\u003e\n        \u003citem\u003e0,35,12,28,\u003c/item\u003e\n        \u003citem\u003e0,21,12,28,\u003c/item\u003e\n        \u003citem\u003e12,28,24,21,\u003c/item\u003e\n        \u003citem\u003e24,35,24,21,\u003c/item\u003e\n        \u003citem\u003e24,21,12,14,\u003c/item\u003e\n        \u003citem\u003e0,21,12,14,\u003c/item\u003e\n        \u003citem\u003e0,21,0,7,\u003c/item\u003e\n        \u003citem\u003e12,14,0,7,\u003c/item\u003e\n        \u003citem\u003e12,14,24,7,\u003c/item\u003e\n        \u003citem\u003e24,7,12,0,\u003c/item\u003e\n        \u003citem\u003e0,7,12,0,\u003c/item\u003e\n    \u003c/string-array\u003e\n\u003c/resources\u003e\n```\n\n# 处理刷新\n\n通过`PtrHandler`，可以检查确定是否可以下来刷新以及在合适的时间刷新数据。\n\n检查是否可以下拉刷新在`PtrDefaultHandler.checkContentCanBePulledDown`中有默认简单的实现，你可以根据实际情况完成这个逻辑。\n\n```\npublic interface PtrHandler {\n\n    /**\n     * 检查是否可以执行下来刷新，比如列表为空或者列表第一项在最上面时。\n     * \u003cp/\u003e\n     * {@link in.srain.cube.views.ptr.PtrDefaultHandler#checkContentCanBePulledDown}\n     */\n    public boolean checkCanDoRefresh(final PtrFrameLayout frame, final View content, final View header);\n\n    /**\n     * 需要加载数据时触发\n     *\n     * @param frame\n     */\n    public void onRefreshBegin(final PtrFrameLayout frame);\n}\n```\n\n例子:\n\n```java\nptrFrame.setPtrHandler(new PtrHandler() {\n    @Override\n    public void onRefreshBegin(PtrFrameLayout frame) {\n        frame.postDelayed(new Runnable() {\n            @Override\n            public void run() {\n                ptrFrame.refreshComplete();\n            }\n        }, 1800);\n    }\n\n    @Override\n    public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {\n        // 默认实现，根据实际情况做改动\n        return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);\n    }\n});\n```\n\n# 常见问题\n\n*  ViewPager滑动冲突: `disableWhenHorizontalMove()`\n\n*  长按LongPressed, `setInterceptEventWhileWorking()`\n\n\n# 联系方式和问题建议\n\n* 微博: http://weibo.com/liaohuqiu\n* QQ 群: \n\n    1. cube系列开源项目使用交流，问题解答: 271918140 (cube-sdk)\n\n        加群前请先阅读群约定: https://github.com/liaohuqiu/qq-tribe-rule\n\n    2. 如果你会通过google解决问题，喜欢独立思考，喜欢和优秀却又温和的人成为朋友，欢迎加入我们在 Slack 上的群组: 我们在 Slack 上的群组: \n    \n        http://join-add1bit.liaohuqiu.net/?channel=git-android-ultra-ptr\n\n* srain@php.net\n* twitter: https://twitter.com/liaohuqiu\n* blog: http://www.liaohuqiu.net\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliaohuqiu%2Fandroid-Ultra-Pull-To-Refresh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliaohuqiu%2Fandroid-Ultra-Pull-To-Refresh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliaohuqiu%2Fandroid-Ultra-Pull-To-Refresh/lists"}