{"id":13641739,"url":"https://github.com/jeasonlzy/HeaderViewPager","last_synced_at":"2025-04-20T11:32:01.590Z","repository":{"id":122731203,"uuid":"52379933","full_name":"jeasonlzy/HeaderViewPager","owner":"jeasonlzy","description":"具有共同头部的 ViewPager，支持与ListView，GridView，ScrollView，WebView，RecyclerView 嵌套使用。具有连续的滑动事件 和 滑动监听， 支持下拉刷新。","archived":false,"fork":false,"pushed_at":"2017-03-29T06:15:05.000Z","size":4649,"stargazers_count":767,"open_issues_count":35,"forks_count":178,"subscribers_count":24,"default_branch":"master","last_synced_at":"2024-08-03T01:24:35.665Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeasonlzy.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-02-23T17:58:46.000Z","updated_at":"2024-05-17T12:34:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"4085b6c3-c4cc-44a7-b19a-e1ca33448765","html_url":"https://github.com/jeasonlzy/HeaderViewPager","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeasonlzy%2FHeaderViewPager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeasonlzy%2FHeaderViewPager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeasonlzy%2FHeaderViewPager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeasonlzy%2FHeaderViewPager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeasonlzy","download_url":"https://codeload.github.com/jeasonlzy/HeaderViewPager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223827605,"owners_count":17209815,"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:23.683Z","updated_at":"2024-11-09T12:31:00.551Z","avatar_url":"https://github.com/jeasonlzy.png","language":"Java","funding_links":[],"categories":["ViewPager"],"sub_categories":[],"readme":"# HeaderViewPager\n###具有共同头部的 ViewPager，支持与ListView，GridView，ScrollView，WebView，RecyclerView 嵌套使用。具有连续的滑动事件 和 滑动监听， 支持下拉刷新。\n\n该项目参考了：[https://github.com/cpoopc/ScrollableLayout](https://github.com/cpoopc/ScrollableLayout) 喜欢原作的可以去使用。相比原项目，代码更简单易懂，扩展性更高，欢迎大家下载体验本项目，如果使用过程中遇到什么问题，欢迎反馈。\n\n## 演示\n ![image](http://7xss53.com2.z0.glb.clouddn.com/headerviewpager/demo1.png) ![image](http://7xss53.com2.z0.glb.clouddn.com/headerviewpager/demo2.gif) ![image](http://7xss53.com2.z0.glb.clouddn.com/headerviewpager/demo3.gif)\n## 1.用法\n该项目和我github上其他的view相关的项目已经一起打包上传到jCenter仓库中（源码地址 [https://github.com/jeasonlzy0216/ViewCore](https://github.com/jeasonlzy0216/ViewCore) ），使用的时候可以直接使用compile依赖，用法如下\n###该项目中使用到的大部分自定义控件，均来源于上述仓库\n```java\n\tcompile 'com.lzy.widget:view-core:0.2.1'\n```\n或者使用\n```java\n    compile project(':header_viewpager')\n```\n\n## 2.实现原理\n把自定义控件 `HeaderViewPagerLayout` 的 `dispatchTouchEvent` 方法进行重写，根据手势方向决定是否分发事件，同时使用 Scroller 滚动内部视图，达到滑动的连续性。 具体详细代码，实例代码中会有详细注释。\n\n## 3.代码参考\n### 1.布局解析\n * 自定义控件`HeaderViewPagerLayout`作为根布局\n * 无论控件具有多少个子`View`,只有第一个子`View`会被自定义控件按头部解析，所以，如果头部有多个`View`，可以使用`ViewGroup`包裹，例如下面实例使用的是`LinearLayout`包裹（头部是一个ViewPager和Indicator指示器），除了第一个`View`会被滑出去外，其余布局均不会被滑出。\n * 如果滑动时，想让布局滑动到一定距离后停止么可以在xml布局中加入自定义属性`app:hvp_topOffset=\"50dp\"`，值的大小表示距离顶部多少距离停止滑动\n * 在头部滑动的过程中，可以使用`setOnScrollListener`设置滑动监听，动态改变头部据或者其他布局的动画\n \n###例如布局中做如下布局：\n```xml\n\t\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cFrameLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n             xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n             android:layout_width=\"match_parent\"\n             android:layout_height=\"match_parent\"\u003e\n\n    \u003ccom.lzy.widget.HeaderViewPager\n        android:id=\"@+id/scrollableLayout\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        android:orientation=\"vertical\"\n        app:hvp_topOffset=\"50dp\"\u003e\n\n        \u003cRelativeLayout\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"200dp\"\u003e\n\n            \u003ccom.lzy.widget.loop.LoopViewPager\n                android:id=\"@+id/pagerHeader\"\n                android:layout_width=\"match_parent\"\n                android:layout_height=\"match_parent\"\n                app:lvp_delayTime=\"2000\"\n                app:lvp_isAutoLoop=\"true\"/\u003e\n\n            \u003ccom.lzy.widget.tab.CircleIndicator\n                android:id=\"@+id/ci\"\n                android:layout_width=\"match_parent\"\n                android:layout_height=\"20dp\"\n                android:layout_alignParentBottom=\"true\"\n                android:background=\"#4000\"\n                app:ci_normalRadiusColor=\"#FFF\"\n                app:ci_selectedRadiusColor=\"#FFF\"/\u003e\n        \u003c/RelativeLayout\u003e\n\n        \u003ccom.lzy.widget.tab.PagerSlidingTabStrip\n            android:id=\"@+id/tabs\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"40dp\"\n            android:background=\"@mipmap/bg_menu_normal\"\n            android:textSize=\"16sp\"\n            app:pstsDividerColor=\"#00000000\"\n            app:pstsIndicatorColor=\"#2DA4F0\"\n            app:pstsIndicatorHeight=\"2dp\"\n            app:pstsShouldExpand=\"false\"\n            app:pstsTextAllCaps=\"false\"\n            app:pstsUnderlineHeight=\"2dp\"/\u003e\n\n        \u003candroid.support.v4.view.ViewPager\n            android:id=\"@+id/viewPager\"\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"match_parent\"/\u003e\n    \u003c/com.lzy.widget.HeaderViewPager\u003e\n\n    \u003cinclude\n        android:id=\"@+id/titleBar\"\n        layout=\"@layout/include_titlebar\"/\u003e\n\u003c/FrameLayout\u003e\n```\n### 2.对于自定义控件，需要做如下初始化\n```java\n\tscrollableLayout.setCurrentScrollableContainer(fragments.get(0));\n    viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {\n        @Override\n        public void onPageSelected(int position) {\n            scrollableLayout.setCurrentScrollableContainer(fragments.get(position));\n        }\n    });\n```\n### 3.如果需要对滑动过程进行监听，可以使用如下代码,currentY 表示当前滑过的距离，maxY表示当前可以滑动的最大距离，有了这两个参数，就可以对任意布局，做任何动画了。例如如下代码就是实现 视差动画效果的代码。\n```xml\n\tscrollableLayout.setOnScrollListener(new HeaderViewPagerLayout.OnScrollListener() {\n        @Override\n        public void onScroll(int currentY, int maxY) {\n            image.setTranslationY(currentY / 2);\n        }\n    });\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeasonlzy%2FHeaderViewPager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeasonlzy%2FHeaderViewPager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeasonlzy%2FHeaderViewPager/lists"}