Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wobiancao/StickyDemo
三步实现控件悬浮
https://github.com/wobiancao/StickyDemo
Last synced: about 1 month ago
JSON representation
三步实现控件悬浮
- Host: GitHub
- URL: https://github.com/wobiancao/StickyDemo
- Owner: wobiancao
- Created: 2017-04-27T09:43:34.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-04-28T01:36:59.000Z (over 7 years ago)
- Last Synced: 2024-08-02T01:25:34.729Z (4 months ago)
- Language: Java
- Size: 1.22 MB
- Stars: 91
- Watchers: 4
- Forks: 18
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-github-android-ui - StickyDemo - 三步实现控件悬浮 (其他)
README
# StickyDemo
三步实现控件悬浮
之前做项目的时候实现的一个悬浮效果,如图(可能不够清晰)
![meibei.gif](http://upload-images.jianshu.io/upload_images/1216032-05d8f2b54825f593.gif?imageMogr2/auto-orient/strip)
*接下来就是实现效果,如图所示*
![sticky.gif](http://upload-images.jianshu.io/upload_images/1216032-ffe9839fa6ec0c84.gif?imageMogr2/auto-orient/strip)
`demo直接用的截图`原理很简单,用RecyclerView addHeaderView的方式实现,实现步骤:
>1.添加依赖
```
compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.14'
compile 'com.android.support:recyclerview-v7:25.1.0'
```
导入BaseRecyclerViewAdapterHelper,用于RecyclerView添加HeaderView;>2.布局,用标签include,写入需要悬浮的view;主界面用帧布局FrameLayout
```
```;
然后布局headerView
```
```>3.逻辑,滑动的时候,对RecyclerView进行滑动监听然后在onScrollStateChanged(RecyclerView recyclerView, int newState)方法里监听悬浮View在
``屏幕上Y轴位移``,在onScrolled(RecyclerView recyclerView, int dx, int dy)里不停的获取headerView里面悬浮标签在``屏幕上Y轴位移``,
进行判断悬浮view的显示或隐藏
if (mHeaderView == null) return;
int getTop = mHeaderView.getDistanceY();
if (getTop <= imageY) {
mImageView.setVisibility(View.VISIBLE);
} else {
mImageView.setY(0);
mImageView.setVisibility(View.GONE);
}
[简书地址](http://www.jianshu.com/p/167507486ff2)
[apk下载](https://fir.im/sticky)