{"id":13641460,"url":"https://github.com/LuckyJayce/CoolRefreshView","last_synced_at":"2025-04-20T11:31:04.229Z","repository":{"id":84779083,"uuid":"75167066","full_name":"LuckyJayce/CoolRefreshView","owner":"LuckyJayce","description":"Android RefreshView Library,support all view to refresh,custom refresh header，implement NestedScrollingParent and NestedScrollingChild ","archived":false,"fork":false,"pushed_at":"2018-11-07T19:00:59.000Z","size":9135,"stargazers_count":191,"open_issues_count":5,"forks_count":39,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-11-01T21:42:49.321Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LuckyJayce.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","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-11-30T08:30:20.000Z","updated_at":"2023-08-03T07:16:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"37ef38e8-b918-415f-bb2a-4d465adf700a","html_url":"https://github.com/LuckyJayce/CoolRefreshView","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LuckyJayce%2FCoolRefreshView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LuckyJayce%2FCoolRefreshView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LuckyJayce%2FCoolRefreshView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LuckyJayce%2FCoolRefreshView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LuckyJayce","download_url":"https://codeload.github.com/LuckyJayce/CoolRefreshView/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:20.906Z","updated_at":"2024-11-09T12:30:17.664Z","avatar_url":"https://github.com/LuckyJayce.png","language":"Java","readme":"CoolRefreshView\n===============  \n\n###1. 支持任意View的刷新  \n###2. 支持自定义Header\n###3. 支持NestedScrollingParent,NestedScrollingChild的事件分发\n###4. 嵌套ViewPager不会有事件冲突  \n\n\n###7.导入方式\n\u003c1\u003egradle导入      \n\n    compile 'com.shizhefei:CoolRefreshView:1.0.4'\n    由于用到了v4和recyclerview所以也要导入他们  \n    compile 'com.android.support:support-v4:23.4.0'  \n\n\u003c2\u003ejar包方式导入  \n\nDownload sample [Apk](https://github.com/LuckyJayce/CoolRefreshView/blob/master/raw/CoolRefreshView.apk?raw=true)   \n\n###8.历史版本和更新信息  \nhttps://github.com/LuckyJayce/CoolRefreshView/releases\n\n\n# 效果图 #\n![image](raw/coolrecyclerview.gif)\n\n\n# 使用方法  \nxml\n\n     \u003ccom.shizhefei.view.coolrefreshview.CoolRefreshView\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\u003e\n\n        \u003candroid.support.v7.widget.RecyclerView\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"match_parent\"/\u003e\n\n    \u003c/com.shizhefei.view.coolrefreshview.CoolRefreshView\u003e\n\n代码\n\n     coolRefreshView.setPullHeader(new MaterialHeader(getContext()));\n     //添加刷新监听\n     coolRefreshView.addOnPullListener(new SimpleOnPullListener() {\n            @Override\n            public void onRefreshing(CoolRefreshView refreshView) {\n                \n            }\n        });\n\n# 其它可用方法  \n\n设置全局的IPullHeaderFactory\n\n\n\t  //静态设置全局的IPullHeaderFactory，一次配置，所有默认使用这个factory生成的PullHeader\n\t  //就不用每个界面设置，该代码可以放在Application onCreate\n\n\t  CoolRefreshView.setPullHeaderFactory(new IPullHeaderFactory() {\n\t      @Override\n\t      public PullHeader made(Context context) {\n\t          JellyHeader jellyHeader = new JellyHeader(getContext());\n\t          jellyHeader.setDragLayoutColor(ContextCompat.getColor(getContext(), R.color.primary));\n\t          jellyHeader.setLoadingView(R.layout.layout_jelley_header);\n\t          return jellyHeader;\n\t      }\n\t\n\t      @Override\n\t      public boolean isPinContent() {\n\t          return false;\n\t      }\n\t  });\n设置ContentView是否和头部一起下拉\n\n    /**\n     * @param pullHeader   刷新的头部\n     * @param isPinContent true滚定内容不下拉，只下拉头部， false 一起下拉\n     */\n    setPullHeader(PullHeader pullHeader, boolean isPinContent) \n\n# 自定义Header\n##\u003c1\u003e简单的实现  \n实现PullHeader\n\n\tpublic class TestHeader implements PullHeader {\n\t    private View headView;\n\t    private TextView mTextView;\n\t\n\t    @Override\n\t    public View createHeaderView(final CoolRefreshView refreshView) {\n\t        headView = LayoutInflater.from(refreshView.getContext()).inflate(R.layout.coolrecyclerview_testhead, refreshView, false);\n\t        mTextView = (TextView) headView.findViewById(R.id.coolrecyclerview_testhead_text1_textView);\n\t        return headView;\n\t    }\n\t\n\t    /**\n\t     * 开始拖动\n\t     */\n\t    @Override\n\t    public void onPullBegin(CoolRefreshView refreshView) {\n\t        isDownArrow = true;\n\t    }\n\t\n\t    /**\n\t     * 位置变化\n\t     *\n\t     * @param refreshView\n\t     * @param status          状态 /没有任何操作\n\t     *                        public final static byte PULL_STATUS_INIT = 1;\n\t     *                        //开始下拉\n\t     *                        public final static byte PULL_STATUS_TOUCH_MOVE = 2;\n\t     *                        //回到原始位置\n\t     *                        public final static byte PULL_STATUS_RESET = 3;\n\t     *                        //刷新中\n\t     *                        public final static byte PULL_STATUS_REFRESHING = 4;\n\t     *                        //刷新完成\n\t     *                        public final static byte PULL_STATUS_COMPLETE = 5;\n\t     * @param dy              下拉事件的位移\n\t     * @param currentDistance 当前位移的距离\n\t     */\n\t    @Override\n\t    public void onPositionChange(CoolRefreshView refreshView, int status, int dy, int currentDistance) {\n\t        int offsetToRefresh = getConfig().offsetToRefresh(refreshView, headView);\n\t        if (status == CoolRefreshView.PULL_STATUS_TOUCH_MOVE) {\n\t            if (currentDistance \u003c offsetToRefresh) {\n\t                if (!isDownArrow) {\n\t                    mTextView.setText(\"下拉刷新\");\n\t                    isDownArrow = true;\n\t                }\n\t            } else {\n\t                if (isDownArrow) {\n\t                    mTextView.setText(\"释放立即刷新\");\n\t                    isDownArrow = false;\n\t                }\n\t            }\n\t        }\n\t    }\n\t\n\t    private boolean isDownArrow;\n\t\n\t    /**\n\t     * 刷新中\n\t     */\n\t    @Override\n\t    public void onRefreshing(CoolRefreshView refreshView) {\n\t        mTextView.setText(\"刷新中..\");\n\t    }\n\t\n\t    /**\n\t     * 没有刷新的释放回去\n\t     */\n\t    @Override\n\t    public void onReset(CoolRefreshView refreshView, boolean pullRelease) {\n\t\n\t    }\n\t\n\t    /**\n\t     * 设置刷新完成，并且释放回去\n\t     */\n\t    @Override\n\t    public void onPullRefreshComplete(CoolRefreshView frame) {\n\t\n\t    }\n\t\n\t    @Override\n\t    public Config getConfig() {\n\t        return config;\n\t    }\n\t\n\t\t//使用默认的配置\n\t    private DefaultConfig config = new DefaultConfig();\n\t\n\t}\n\n也可以直接继承View 实现 PullHeader\n\n\tpublic class TestHeader extends View  implements PullHeader {\n\t    @Override\n\t    public View createHeaderView(final CoolRefreshView refreshView) {\n\t        return this;\n\t    }\n\t}\n\n##\u003c2\u003e配置距离，可以实现更丰富的效果\n\n\t abstract class Config {\n\t        /**\n\t         * 超出这个偏移量，松开手指就会触发刷新。\n\t         */\n\t        public abstract int offsetToRefresh(CoolRefreshView refreshView, View headerView);\n\t\n\t        /**\n\t         * 显示刷新的位置的偏移量\n\t         */\n\t        public abstract int offsetToKeepHeaderWhileLoading(CoolRefreshView refreshView, View headerView);\n\t\n\t        /**\n\t         * 刷新控件总共可以下拉拖动的距离\n\t         */\n\t        public abstract int totalDistance(CoolRefreshView refreshView, View headerView);\n\t\n\t        /**\n\t         * headView 在布局中的偏移量\n\t         */\n\t        public abstract int headerViewLayoutOffset(CoolRefreshView refreshView, View headerView);\n\t\n\t        /**\n\t         * contentView 是否可以向上滚动，用来判断是否可以下拉刷新，如果可以向上滚动就不做下拉刷新动作\n\t         */\n\t        public abstract boolean contentCanScrollUp(CoolRefreshView refreshView, View contentView);\n\t\n\t        /**\n\t         * 拦截滑动事件\n\t         *\n\t         * @param refreshView\n\t         * @param dy              触摸滑动的偏移量\n\t         * @param currentDistance 当前的滑动的距离\n\t         * @param totalDistance   总的可下拉距离\n\t         * @return\n\t         */\n\t        public abstract int dispatchTouchMove(CoolRefreshView refreshView, int dy, int currentDistance, int totalDistance);\n\t\n\t    }\n\n  **默认的配置**\n\n    //滑动的总距离是header高度3倍\n    //触发刷新的距离是header的1.2倍\n    //正在刷新中的距离是header的高度\n\tclass DefaultConfig extends Config {\n\n        @Override\n        public int offsetToRefresh(CoolRefreshView refreshView, View headerView) {\n            return (int) (headerView.getMeasuredHeight() * 1.2f);\n        }\n\n        @Override\n        public int offsetToKeepHeaderWhileLoading(CoolRefreshView refreshView, View headerView) {\n            return headerView.getMeasuredHeight();\n        }\n\n        @Override\n        public int totalDistance(CoolRefreshView refreshView, View headerView) {\n            return headerView.getMeasuredHeight() * 3;\n        }\n\n\t\t.....\n    }\n\n  **第二种常用的配置**\n\n    //总的滑动是header的高度，也就是滑动显示的区域控制在header里\n    //正在刷新的距离是header3分之一，在header底部的3分之一区域作为正在刷新中的区域\n    //触发刷新的距离是正在刷新距离的1.2倍.\n\n \tprivate DefaultConfig config = new DefaultConfig() {\n        @Override\n        public int offsetToRefresh(CoolRefreshView refreshView, View headerView) {\n            return (int) (headerView.getMeasuredHeight() / 3 * 1.2f);\n        }\n\n        @Override\n        public int offsetToKeepHeaderWhileLoading(CoolRefreshView refreshView, View headerView) {\n            return headerView.getMeasuredHeight() / 3;\n        }\n\n        @Override\n        public int totalDistance(CoolRefreshView refreshView, View headerView) {\n            return headerView.getMeasuredHeight();\n        }\n    };\n\n##配合MVCHelper类库使用，上滑加载更多\n配合\nhttps://github.com/LuckyJayce/MVCHelper   \n代码只要5行，就可以实现下拉刷新，滚动底部自动加载更多，分页加载，自动切换显示网络失败布局，暂无数据布局\n\n    CoolRefreshView coolRefreshView = (CoolRefreshView) findViewById(R.id.coolRefreshView);\n    MVCHelper\u003cList\u003cBook\u003e\u003e mvcHelper = new MVCCoolHelper\u003cList\u003cBook\u003e\u003e(coolRefreshView);\n\n    // 设置数据源\n    mvcHelper.setDataSource(new BooksDataSource());\n    // 设置适配器\n    mvcHelper.setAdapter(new BooksAdapter(this));\n\n    // 加载数据\n    mvcHelper.refresh();\n\n更多的详细使用参照 https://github.com/LuckyJayce/MVCHelper 的demo\n\n\n## 说明\n\n  滑动事件的处理是参照 v4包的 SwipeRefreshLayout，从而支持了支持NestedScrollingParent,NestedScrollingChild的事件分发和避免了嵌套 ViewPager事件冲突  \n\n  结构是参考  https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh 的结构，它的结构很不错。可以让使用者根据需求自定义Header\n\n  Header的下拉我采用了两种实现  \n  \u003c1\u003eHeader下拉，内容固定不下拉采用 ViewCompat.offsetTopAndBottom(mHeaderView, -deltaY);  \n  \u003c2\u003eHeader和内容一起下拉的采用 scrollTo的方式一起滑动.\n\n\n  \n\n\n##主力类库##\n\n**1.https://github.com/LuckyJayce/ViewPagerIndicator**  \nIndicator 取代 tabhost，实现网易顶部tab，新浪微博主页底部tab，引导页，无限轮播banner等效果，高度自定义tab和特效\n\n**2.https://github.com/LuckyJayce/MVCHelper**  \n实现下拉刷新，滚动底部自动加载更多，分页加载，自动切换显示网络失败布局，暂无数据布局，支持任意view，支持切换主流下拉刷新框架。\n\n**3.https://github.com/LuckyJayce/MultiTypeView**  \n简化RecyclerView的多种type的adapter，Fragment可以动态添加到RecyclerView上，实现复杂的界面分多个模块开发\n\n**4.https://github.com/LuckyJayce/EventBus**  \n事件总线，通过动态代理接口的形式发布,接收事件。定义一个接口把事件发给注册并实现接口的类\n\n**5.https://github.com/LuckyJayce/LargeImage**  \n大图加载，可供学习\n\n**6.https://github.com/LuckyJayce/GuideHelper**  \n新手引导页，轻松的实现对应的view上面的显示提示信息和展示功能给用户  \n\n**7.https://github.com/LuckyJayce/HVScrollView**  \n可以双向滚动的ScrollView，支持嵌套ScrollView联级滑动，支持设置支持的滚动方向\n\n**8.https://github.com/LuckyJayce/CoolRefreshView**  \n  下拉刷新RefreshView，支持任意View的刷新 ，支持自定义Header，支持NestedScrollingParent,NestedScrollingChild的事件分发，嵌套ViewPager不会有事件冲突 \n\n有了这些类库，让你6的飞起\n\n## 说明 ##\n项目 ViewPagerIndicator_Demo 是示例代码。 看了这个例子你会惊奇的发现里面居然都是通过viewpager实现，没有使用tabhost，而所有形式的tab都是用Indicator实现。\n项目 ViewPagerIndicator_Library 是类库\n\n有什么建议可以发到我的邮箱  794629068@qq.com  \n\n# 联系方式和问题建议\n\n* 微博:http://weibo.com/u/3181073384\n* QQ 群: 开源项目使用交流，问题解答: 549284336\n\nLicense\n=======\n\n\t/*\n\t * Copyright (C) 2016 LuckyJayce\n\t * Copyright (C) 2016 liaohuqiu\n\t * Copyright (C) 2013 The Android Open Source Project\n\t *\n\t * Licensed under the Apache License, Version 2.0 (the \"License\");\n\t * you may not use this file except in compliance with the License.\n\t * You may obtain a copy of the License at\n\t *\n\t *      http://www.apache.org/licenses/LICENSE-2.0\n\t *\n\t * Unless required by applicable law or agreed to in writing, software\n\t * distributed under the License is distributed on an \"AS IS\" BASIS,\n\t * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\t * See the License for the specific language governing permissions and\n\t * limitations under the License.\n\t */\n","funding_links":[],"categories":["下拉刷新"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLuckyJayce%2FCoolRefreshView","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLuckyJayce%2FCoolRefreshView","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLuckyJayce%2FCoolRefreshView/lists"}