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.5.4-RedisDump的安装
RedisDump是一个用于Redis数据导入/导出的工具,是基于Ruby实现的,所以要安装RedisDump,需要先安装Ruby. 1. 相关链接 GitHub:https://github.com ...
- 树莓派 -- 按键 (key)使用BCM2835 gpio library
BCM2835 GPIO library介绍 This is a C library for Raspberry Pi (RPi). It provides access to GPIO and ot ...
- ubuntu lamnp 环境的安装/卸载 及 配置
安装mysql--------------------------------------sudo apt install mysql-server #5.7版本 安装php----------- ...
- 合办大学 -- internal campus in China
* 合办大学 -- internal campus in China- international campus zhejiang University- 南方科技大学 - 西交利物浦大学(Xi’an ...
- 杭电 1862 EXCEL排序(sort+结构体)
Description Excel可以对一组纪录按任意指定列排序.现请你编写程序实现类似功能. Input 测试输入包含若干测试用例.每个测试用例的第1行包含两个整数 N (<=100000 ...
- popup介绍
一.作用 用于使浏览器自动生成弹窗 二.示例 1.新建Django项目,新建APP:app01, 项目根目录下新建文件夹static 2.静态文件配置,在settings.py中配置static: 3 ...
- 【04】 CSS开发注意事项
[04] CSS注意事项 1. 页面编码规范 1.1. 统一使用 UTF-8 编码,用@charset "utf-8"指定页面编码. 1.2. 全局字体设置: windows 7系 ...
- [codevs4655] 序列终结者(Splay)
传送门 支持操作: 1.区间加 2.区间翻转 3.区间求最大值 splay模板 注意:update 里更新 max 时需要取 3 个值的 Max 别忘了各种边界讨论 ——代码 #include < ...
- poj 1456
#include<stdio.h> #include<string.h> #include<stdlib.h> #define N 10010 #define in ...
- 【Codevs1237&网络流24题餐巾计划】(费用流)
题意:一个餐厅在相继的 N 天里,每天需用的餐巾数不尽相同. 假设第 i 天需要 ri块餐巾(i=1,2,…,N).餐厅可以购买新的餐巾,每块餐巾的费用为 p 分: 或者把旧餐巾送到快洗部,洗一块需 ...