{"id":13641488,"url":"https://github.com/HitenDev/VRefreshLayout","last_synced_at":"2025-04-20T11:31:09.021Z","repository":{"id":89365639,"uuid":"75468687","full_name":"HitenDev/VRefreshLayout","owner":"HitenDev","description":"This is an android library be used when the user refresh vertical layout.","archived":false,"fork":false,"pushed_at":"2016-12-07T14:20:38.000Z","size":2588,"stargazers_count":88,"open_issues_count":1,"forks_count":21,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-08-04T00:04:55.218Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HitenDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-12-03T11:05:10.000Z","updated_at":"2024-08-04T00:04:55.218Z","dependencies_parsed_at":"2024-01-14T11:07:20.875Z","dependency_job_id":"d506318c-7d3a-4103-817d-68efd625a781","html_url":"https://github.com/HitenDev/VRefreshLayout","commit_stats":null,"previous_names":["ileelay/vrefreshlayout"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HitenDev%2FVRefreshLayout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HitenDev%2FVRefreshLayout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HitenDev%2FVRefreshLayout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HitenDev%2FVRefreshLayout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HitenDev","download_url":"https://codeload.github.com/HitenDev/VRefreshLayout/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223827350,"owners_count":17209777,"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-08-02T01:01:21.155Z","updated_at":"2024-11-09T12:30:17.310Z","avatar_url":"https://github.com/HitenDev.png","language":"Java","readme":"# VRefreshLayout\n一个竖直方向的下拉刷新控件，支持自定义Header，可配置参数，最重要的特点是**刷新时头部置顶显示，且不影响列表滑动**；\n\n## 为什么要做头部置顶显示\n现在越来越多的App下拉刷新时是置顶显示的，大家可以看`手机京东`,`天猫商城`,`小米商城`,`汽车之家`等APP，我们在下拉刷新时，头部的刷新视图是保持显示的，这样在滚动列表的时候，用户可以知道当前正在刷新状态，而传统的下拉刷新库，比如[Android-PullToRefresh](https://github.com/chrisbanes/Android-PullToRefresh)和[android-Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh)，是不支持的头部置顶显示的，用户往下翻看时，刷新状态就可能被隐藏；google的SwpieRefreshLayout是置顶层显示的，但是它的内容区域的不会跟着动的，且可定制性太差。\n\n\n## 功能预览\n\n头部刷新时列表可以正常响应事件，且头部不会隐藏\n\n![](https://github.com/ileelay/VRefreshLayout/blob/master/pics/gif1.gif)\n\n自定义头部样式,例如模仿一个京东的下拉刷新动画\n\n![](https://github.com/ileelay/VRefreshLayout/blob/master/pics/jd.gif)\n\n良好的兼容性，支持ListView/RecyclerView/ScrollView/TextViw/Image等绝大多数view\n\n![](https://github.com/ileelay/VRefreshLayout/blob/master/pics/gif2.gif)\n\n可以配置下拉高度，阻尼度以及各部分动画时长等参数\n\n![](https://github.com/ileelay/VRefreshLayout/blob/master/pics/gif3.gif)\n\n\n## 简单使用\n\n- 在布局中，包裹一个将要刷新的View/ViewGroup\n```java\n \u003ccom.leelay.freshlayout.verticalre.VRefreshLayout\n        android:id=\"@+id/refresh_layout\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        \u003e\n\n        \u003cListView\n            android:id=\"@+id/listView\"\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:background=\"@android:color/white\"\n            /\u003e\n\n    \u003c/com.leelay.freshlayout.verticalre.VRefreshLayout\u003e\n    \n```\njava代码中，监听和控制刷新状态\n```\n mRefreshLayout = (VRefreshLayout) findViewById(R.id.refresh_layout);\n mRefreshLayout.addOnRefreshListener(new VRefreshLayout.OnRefreshListener() {\n                @Override\n                public void onRefresh() {\n                    mRefreshLayout.postDelayed(new Runnable() {\n                        @Override\n                        public void run() {\n                            mRefreshLayout.refreshComplete();\n                        }\n                    }, 2000);\n                }\n            });\n \n\n```\n\n这样就能在下拉时触发刷新时间，2000ms后刷新完成，隐藏刷新状态；\n\n## 方法介绍\n\n- setDragRate(float dragRate)  设置拖拽的阻尼比例，默认是0.5，一般设置在0-1之间比较合适;\n\n- setRatioOfHeaderHeightToRefresh(float ratio)  设置允许刷新的高度和HeaderView高度的比例，默认为1.0;\n\n- setRatioOfHeaderHeightToReach(float ratio) 设置能下拉的最大高度和HeaderView高度的比例，默认为1.6;\n\n- setToStartDuration(int toStartDuration) 设置回到初始状态动画执行时间，单位为ms，默认是200ms;\n\n- setToRetainDuration(int toRetainDuration) 设置手指离开屏幕后触发刷新时到刷新保持的位置需要的动画时长，单位为ms,默认为200ms;\n\n- setAutoRefreshDuration(int autoRefreshDuration) 自动刷新需要的动画时长 ，默认为800ms；\n\n- setCompleteStickDuration(int completeStickDuration) 刷新完成后状态保持的时长，默认为200ms;\n\n- setHeaderView(View view) 设置一个自定义的HeaderView;\n\n- setUpdateHandler(UpdateHandler updateHandler) 设置状态和进度更新处理，一般是Header实现；\n\n- addOnRefreshListener(OnRefreshListener onRefreshListener) 添加一个刷新回调监听，支持add方式；\n\n- refreshComplete() 调用次方法，可以接受刷新；\n\n\n## 自定义HeaderView\n自定义Header只需要集成一个ViewGroup/View，实现VRefreshLayout.UpdateHandler接口即可；\n最基本的代码\n```java\npublic class CustomHeaderView extends ViewGroup implements VRefreshLayout.UpdateHandler{\n    public CustomHeaderView(Context context) {\n        super(context);\n    }\n\n    public CustomHeaderView(Context context, AttributeSet attrs) {\n        super(context, attrs);\n    }\n\n    @Override\n    protected void onLayout(boolean changed, int l, int t, int r, int b) {\n        \n    }\n\n    @Override\n    public void onProgressUpdate(VRefreshLayout layout, VRefreshLayout.Progress progress, int status) {\n\n    }\n}\n```\nUpdateHandler只有一个方法onProgressUpdate(VRefreshLayout layout, VRefreshLayout.Progress progress, int status)，重写它就能监听下拉进度和状态；\n### VRefreshLayout.PProgress\nProgress类一个简单的Entity，其中有三个属性，分别是\n- totalY 可下拉的最大Y方向距离\n- currentY 当前Y方向距离\n- refreshY 触发刷新的距离这些\n- refreshY 触发刷新的距离\n这些距离的参考点是contentView的Top点;\n\n### status状态\n```\npublic final static int STATUS_INIT = 0;//原始状态\npublic final static int STATUS_DRAGGING = 1;//正在下拉\npublic final static int STATUS_RELEASE_PREPARE = 2;//松手将要刷新\npublic final static int STATUS_REFRESHING = 3;//正在刷新\npublic final static int STATUS_RELEASE_CANCEL = 4;//松手取消\npublic final static int STATUS_COMPLETE = 5;//刷新完成\n    \n```\n状态解析：\n- STATUS_INIT 原始状态，发生在MOVE事件之前和刷新完成headerView完全隐藏之后\n- STATUS_DRAGGING 手指拖拽状态，只有在触发下拉后且手指没有完全离开屏幕，发生在这一时间段内；\n- STATUS_RELEASE_PREPARE 拖拽的距离超过可触发刷新的距离，在手指放开到正在刷新之前的这一段时间内；\n- STATUS_REFRESHING 正在刷新，调用refreshComplete()结束该状态；\n- STATUS_COMPLETE 调用refreshComplete()方法开始，到headerView即将完全隐藏之后，这一点时间内\n这些状态正好形成一个状态循环；\n\n\n## 参考\n- [android-Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh) -liaohuqiu\n- [SwipeRefreshLayout](https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html) -google\n","funding_links":[],"categories":["下拉刷新"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHitenDev%2FVRefreshLayout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHitenDev%2FVRefreshLayout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHitenDev%2FVRefreshLayout/lists"}