Recyclerview 顶部悬停 stick
activity布局 ll_top代表要悬停的部分 这里面我放了 图片和文本
1 <?xml version="1.0" encoding="utf-8"?>
2 <RelativeLayout
3 xmlns:android="http://schemas.android.com/apk/res/android"
4 xmlns:tools="http://schemas.android.com/tools"
5 android:layout_width="match_parent"
6 android:layout_height="match_parent"
7 android:paddingBottom="@dimen/activity_vertical_margin"
8 android:paddingLeft="@dimen/activity_horizontal_margin"
9 android:paddingRight="@dimen/activity_horizontal_margin"
10 android:paddingTop="@dimen/activity_vertical_margin"
11 tools:context="com.demon.testservice.ui.RelistActivity">
12
13 <FrameLayout
14 android:layout_width="match_parent"
15 android:layout_height="match_parent">
16
17 <android.support.v7.widget.RecyclerView
18 android:id="@+id/recyclerView"
19 android:layout_width="match_parent"
20 android:layout_height="match_parent">
21
22 </android.support.v7.widget.RecyclerView>
23
24
25 <LinearLayout
26 android:id="@+id/ll_top"
27 android:layout_width="match_parent"
28 android:layout_height="wrap_content"
29 android:orientation="vertical">
30
31
32 <LinearLayout
33 android:layout_width="match_parent"
34 android:layout_height="wrap_content"
35 android:background="@color/white"
36 android:gravity="center_vertical"
37 android:orientation="horizontal">
38
39 <ImageView
40 android:layout_width="30dp"
41 android:layout_height="30dp"
42 android:src="@drawable/ic_launcher"/>
43
44 <TextView
45 android:id="@+id/tv_top"
46 android:layout_width="wrap_content"
47 android:layout_height="wrap_content"
48 android:text="name"/>
49
50 </LinearLayout>
51
52
53 <View
54 android:id="@+id/top_divider"
55 android:layout_width="match_parent"
56 android:layout_height="0.2dp"
57 android:background="#33000000"/>
58
59 </LinearLayout>
60
61
62 </FrameLayout>
63
64
65 </RelativeLayout>
item布局 上面和ll_top一样,下面部分是显示一张大图片
1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="wrap_content"
5 android:orientation="vertical"
6 >
7
8 <LinearLayout
9 android:layout_width="match_parent"
10 android:layout_height="wrap_content"
11 android:gravity="center_vertical"
12 android:orientation="horizontal"
13 android:background="@color/white"
14 >
15
16 <ImageView
17 android:layout_width="30dp"
18 android:layout_height="30dp"
19 android:src="@drawable/ic_launcher"/>
20
21 <TextView
22 android:layout_width="wrap_content"
23 android:layout_height="wrap_content"
24 android:text="name"/>
25
26 </LinearLayout>
27
28 <View
29
30 android:layout_width="match_parent"
31 android:layout_height="0.2dp"
32 android:background="#33000000" />
33
34
35 <ImageView
36 android:paddingTop="5dp"
37 android:layout_width="wrap_content"
38 android:layout_height="wrap_content"
39 android:src="@drawable/user"/>
40
41
42 </LinearLayout>
activity 设置addOnScrollListener 是关键

1 public class RelistActivity extends AppCompatActivity {
2
3 @Bind(R.id.recyclerView)
4 RecyclerView recyclerView;
5
6 @Bind(R.id.ll_top)
7 LinearLayout ll_top;
8
9 @Bind(R.id.tv_top)
10 TextView tv_top;
11
12 private int height;
13 private int currentPosition = 0;
14
15 @Override
16 protected void onCreate(Bundle savedInstanceState) {
17 super.onCreate(savedInstanceState);
18 setContentView(R.layout.activity_relist);
19 ButterKnife.bind(this);
20
21 final LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
22 RelistAdapter adapter=new RelistAdapter();
23
24 recyclerView.setLayoutManager(linearLayoutManager);
25 recyclerView.setAdapter(adapter);
26
27
28 recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
29 @Override
30 public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
31 super.onScrollStateChanged(recyclerView, newState);
32
33 height=ll_top.getHeight();
34
35 }
36
37 @Override
38 public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
39 super.onScrolled(recyclerView, dx, dy);
if (currentPosition!=linearLayoutManager.findFirstVisibleItemPosition()){
51 currentPosition=linearLayoutManager.findFirstVisibleItemPosition();
52 ll_top.setY(0);
53
54 tv_top.setText(" "+currentPosition);
55 }
40 View view=linearLayoutManager.findViewByPosition(currentPosition+1); 41 if (view==null)return; 42 43 if (view.getTop()<=height){ 44 ll_top.setY(-(height-view.getTop())); 45 }else { 46 ll_top.setY(0); 47 } 48 49 50 56 } 57 }); 58 59 } 60 61 62 63 64 65 66 67 class RelistAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{ 68 69 70 @Override 71 public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 72 View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_re,parent,false); 73 return new ReHolder(view); 74 } 75 76 @Override 77 public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 78 79 } 80 81 @Override 82 public int getItemCount() { 83 return 10; 84 } 85 86 class ReHolder extends RecyclerView.ViewHolder{ 87 88 public ReHolder(View itemView) { 89 super(itemView); 90 ButterKnife.bind(this,itemView); 91 } 92 } 93 } 94 95 96 }

Recyclerview 顶部悬停 stick的更多相关文章
- Android滑动到顶部悬停
无图说卵,先上图 jianshu-top.gif 查阅资料后,发现网上大部分都是用这种方法实现的: 多写一个和需要悬浮的部分一模一样的layout,先把浮动区域的可见性设置为gone.当浮动区域滑动到 ...
- Android ScrollView滚动实现大众点评、网易云音乐评论悬停效果
今天听着网易云音乐,写着代码,真是爽翻了. http://blog.csdn.net/linshijun33/article/details/47910833 网易云音乐这个产品亮点应该在评论这一模块 ...
- RecyclerView+FloatingActionButton应用
一.效果图 二.实现步骤 1.XML布局-添加依赖 <LinearLayout android:id="@+id/layout" android:layout_width=& ...
- collectionview cell吸顶效果
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Hiragino Sans GB"; color: #cf8724 } ...
- android动画源码合集、动态主题框架、社交app源码等
Android精选源码 仿MIUI果冻视图-BouncingJellyView 一个快速易用的动态主题框架 android动画效果集合源码 android使用Kotlin开发的Dribbb ...
- 前端面试题总结(js、html、小程序、React、ES6、Vue、算法、全栈热门视频资源)
写在前面 参考答案及资源在看云平台发布,如果大家想领取资源以及查看答案,可直接前去购买.一次购买永久可看,文档长期更新!有什么意见与建议欢迎您及时联系作者或留言回复! 文档描述 本文是关注微信小程序的 ...
- NestedScrollView
参考文章: Android滑动到顶部悬停 NestedScrollView的使用 效果图: 实现步骤: 将需要悬浮的layout放到CollapsingToolbarLayout之外,AppBarLa ...
- 折叠表格思路及遇到的问题(tableView:viewForHeaderInSection:的section从1开始,不是从0开始)
项目需要做了一个类似qq联系人的折叠表格,思路很简单:设置每个section的header,在header上显示组名等信息,然后根据折叠与否,设置每个section中cell的数量,如果折叠,则将之设 ...
- 【iOS开发-58】tableView初识:5个重要方法的使用和2种样式的差别
创建一个tableView,直接拖拽放在storyboard里面就可以. (1)先创建一个数据模型类WSCarGroup,在WSCarGroup.h文件里: #import <Foundatio ...
随机推荐
- [Python3网络爬虫开发实战] 1.4.1-MySQL的安装
MySQL是一个轻量级的关系型数据库,本节中我们来了解下它的安装方式. 1. 相关链接 官方网站:https://www.mysql.com/cn 下载地址:https://www.mysql.com ...
- 分布式集群算法 memcached 如何实现分布式?
memcached 是一个”分布式缓存”,然后 memcached 并不像 mongoDB 那 样,允许配置多个节点,且节点之间”自动分配数据”. 就是说--memcached 节点之间,是不互相通信 ...
- Linux 搭建 squid 代理服务器 三种模式
CentOS 6.7 squid 代理服务器 一般有两张或以上网卡,一张链接公网,访问外网资源,一张位于局域网. 代理服务器可以提供文件缓存.复制和地址过滤等服务,充分利用有限的出口带宽,加快内部主机 ...
- axios增加的自定义header,后端request取不到
1.拦截器配置 <!--拦截器--> <mvc:interceptors> <!-- web端增加头部接口 --> <mvc:interceptor> ...
- [java基础原理] BigDecimal
1.类 简化示例 属于java.math包,因此包含各种数学运算,abs,pow等等. package java.math; public class BigDecimal { //值的绝对long型 ...
- 如何用nfs命令烧写内核和文件系统(网络下载文件到nandflash)(未完)
使用tftp下载烧写 a.设uboot里的ip地址 set ipaddr 192.168.1.17(uboot的ip设置成同网段) set serverip 192.168.1.5(电脑本机作为服务i ...
- 细说php第八章笔记(初稿)
8.1 函数的定义 函数是被命名的: 函数是独立的: 函数执行特定的任务: 函数可以用将一个返回值返回给调用他的程序 函数的优越性 提高程序的重用性 ...
- Fiddler简介与Web抓包,远程抓包(IE、360、谷歌、火狐)
Fiddler简介以及web抓包 一.Fiddler简介 简单来说,Fiddler是一个http协议调试代理工具,它能够记录并检查所有你的电脑和互联网之间的http通讯.网上简介很多,我们不多说. 二 ...
- 下载Spring4.1.x源码并用IntelliJ IDEA打开-----
下载Spring4.1.x源码并用IntelliJ IDEA打开-------https://blog.csdn.net/boling_cavalry/article/details/79426075 ...
- CodeForcesGym 100524A Astronomy Problem
Astronomy Problem Time Limit: 8000ms Memory Limit: 524288KB This problem will be judged on CodeForce ...