{"id":13645662,"url":"https://github.com/wobiancao/StickyDemo","last_synced_at":"2025-04-21T14:32:02.503Z","repository":{"id":212019239,"uuid":"89581899","full_name":"wobiancao/StickyDemo","owner":"wobiancao","description":"三步实现控件悬浮","archived":false,"fork":false,"pushed_at":"2017-04-28T01:36:59.000Z","size":1279,"stargazers_count":91,"open_issues_count":0,"forks_count":18,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-09T18:43:23.100Z","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/wobiancao.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}},"created_at":"2017-04-27T09:43:34.000Z","updated_at":"2021-12-14T06:04:32.000Z","dependencies_parsed_at":"2023-12-12T05:39:55.888Z","dependency_job_id":null,"html_url":"https://github.com/wobiancao/StickyDemo","commit_stats":null,"previous_names":["wobiancao/stickydemo"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wobiancao%2FStickyDemo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wobiancao%2FStickyDemo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wobiancao%2FStickyDemo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wobiancao%2FStickyDemo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wobiancao","download_url":"https://codeload.github.com/wobiancao/StickyDemo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250070253,"owners_count":21369842,"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:02:39.278Z","updated_at":"2025-04-21T14:32:01.925Z","avatar_url":"https://github.com/wobiancao.png","language":"Java","funding_links":[],"categories":["其他"],"sub_categories":[],"readme":"# StickyDemo\n三步实现控件悬浮\n之前做项目的时候实现的一个悬浮效果，如图（可能不够清晰）\n![meibei.gif](http://upload-images.jianshu.io/upload_images/1216032-05d8f2b54825f593.gif?imageMogr2/auto-orient/strip)\n*接下来就是实现效果,如图所示*\n![sticky.gif](http://upload-images.jianshu.io/upload_images/1216032-ffe9839fa6ec0c84.gif?imageMogr2/auto-orient/strip)\n`demo直接用的截图`\n\n原理很简单，用RecyclerView addHeaderView的方式实现，实现步骤：\n\u003e1.添加依赖\n```\n compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.14'\n compile 'com.android.support:recyclerview-v7:25.1.0'\n ```\n导入BaseRecyclerViewAdapterHelper，用于RecyclerView添加HeaderView;\n\n\u003e2.布局，用标签include，写入需要悬浮的view；主界面用帧布局FrameLayout\n```\n\u003cFrameLayout\n       android:layout_width=\"match_parent\"\n       android:layout_height=\"match_parent\"\u003e\n       \u003candroid.support.v7.widget.RecyclerView\n           android:id=\"@+id/main_recycler\"\n           android:layout_width=\"match_parent\"\n           android:layout_height=\"match_parent\"/\u003e\n    \u003cinclude layout=\"@layout/include_header_product\"/\u003e\n   \u003c/FrameLayout\u003e \n\t ```;\n然后布局headerView\n```\n\u003cImageView\n        android:layout_width=\"wrap_content\"\n        android:src=\"@mipmap/img_header_category\"\n        android:adjustViewBounds=\"true\"\n        android:layout_height=\"wrap_content\"/\u003e\n    \u003cinclude layout=\"@layout/include_header_product\"/\u003e\n\t\t```\n\n\u003e3.逻辑，滑动的时候，对RecyclerView进行滑动监听然后在onScrollStateChanged(RecyclerView recyclerView, int newState)方法里监听悬浮View在\n``屏幕上Y轴位移``，在onScrolled(RecyclerView recyclerView, int dx, int dy)里不停的获取headerView里面悬浮标签在``屏幕上Y轴位移``,\n进行判断悬浮view的显示或隐藏\nif (mHeaderView == null) return;\n                int getTop = mHeaderView.getDistanceY();\n                if (getTop \u003c= imageY) {\n                    mImageView.setVisibility(View.VISIBLE);\n                } else {\n                    mImageView.setY(0);\n                    mImageView.setVisibility(View.GONE);\n                }\n\t\t\t\t\t\t\t\t\n\n[简书地址](http://www.jianshu.com/p/167507486ff2)\n\n[apk下载](https://fir.im/sticky)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwobiancao%2FStickyDemo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwobiancao%2FStickyDemo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwobiancao%2FStickyDemo/lists"}