SectionIndexer中的getSectionForPosition()与getPositionForSection()解惑
大家在做字母索引的时候常常会用到SectionIndexer这个类,里面有2个重要的方法
1. getSectionForPosition()通过该项的位置,获得所在分类组的索引号
2. getPositionForSection() 根据分类列的索引号获得该序列的首个位置
getSectionForPosition(0) 返回 0
getSectionForPosition(1) 返回 0
getSectionForPosition(2) 返回 0
getSectionForPosition(3) 返回 1
这下,明白这两个方法的区别了把
所以一般有如下代码,来确定是否滑动到了分类的首字母位置
- public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
- int totalItemCount) {
- int section = indexer.getSectionForPosition(firstVisibleItem); //获得索引号
- int nextSecPosition = indexer.getPositionForSection(section + 1); //根据索引号获得下一个索引的初始位置
- if (firstVisibleItem != lastFirstVisibleItem) {
- MarginLayoutParams params = (MarginLayoutParams) titleLayout.getLayoutParams();
- params.topMargin = 0;
- titleLayout.setLayoutParams(params);
- title.setText(String.valueOf(alphabet.charAt(section)));
- }
- if (nextSecPosition == firstVisibleItem + 1) { //若是下一个索引号的位置与当前所见的项+1,则进行位移
- View childView = view.getChildAt(0);
- if (childView != null) {
- int titleHeight = titleLayout.getHeight();
- int bottom = childView.getBottom();
- MarginLayoutParams params = (MarginLayoutParams) titleLayout
- .getLayoutParams();
- if (bottom < titleHeight) {
- float pushedDistance = bottom - titleHeight;
- params.topMargin = (int) pushedDistance;
- titleLayout.setLayoutParams(params);
- } else {
- if (params.topMargin != 0) {
- params.topMargin = 0;
- titleLayout.setLayoutParams(params);
- }
- }
- }
- }
- lastFirstVisibleItem = firstVisibleItem;
- }
- });
SectionIndexer中的getSectionForPosition()与getPositionForSection()解惑相关推荐
- SectionIndexer中的getSectionForPosition()与getPositionForSection()
大家在做字母索引的时候常常会用到SectionIndexer这个类,里面有2个重要的方法 1. getSectionForPosition()通过该项的位置,获得所在分类组的索引号 2. getP ...
- DM中一个热门问题的解惑
宇宙之大,万事万物概莫变化无常.模型作为一种抽象的工具,远在几千年前我们的老祖宗就已经意识到其作用,人们制造瓷器.陶器.铜器.金器.银器等等,都要首先制作各种"模子".进而推广之, ...
- java中date类型如何赋值_Java 中的类型传递问题解惑
点击上方☝SpringForAll社区 轻松关注!及时获取有趣有料的技术文章 来源: https://blog.biezhi.me/2018/11/java-pass-by-value.html 我之 ...
- gmap mysql cachet_MySQL中binlog cache使用流程解惑
水平有限整理自己的学习笔记,如果有误请谅解. 最近老是看到有朋友报错如下: ERROR 1197 (HY000): Multi-statement transaction required more ...
- listview-联系人列表
源码: http://download.csdn.net/detail/sinat_31057219/9735995 参考: Android进阶--字符串排序 Android ListView侧边字母 ...
- GNU Make 使用手册(于凤昌中译版)
GNU Make 使用手册(中译版) 翻译:于凤昌 GNU make Version 3.79 April 2000 Richard M. Stallman and Roland McGrath 1 ...
- Android系统联系人全特效实现(上),分组导航和挤压动画
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/9033553 记得在我刚接触Android的时候对系统联系人中的特效很感兴趣,它会根 ...
- springboot项目层次结构_Spring Boot 默认的指标数据从哪来的?
点击上方☝SpringForAll社区 轻松关注!及时获取有趣有料的技术文章 了解有关 Spring Boot 默认指标及其来源的更多信息. 您是否注意到 Spring Boot 和 Micromet ...
- boost源码剖析之:Tuple Types(rev#2)
boost源码剖析之:Tuple Types(rev#2) 刘未鹏(pongba) C++的罗浮宫(http://blog.csdn.net/pongba) Note: 并非新作,04年曾放在 ...
最新文章
- 一次搞定:分布式缓存 Redis 集群搭建!
- linux mint cinnamon_最佳 Linux 发行版汇总
- 利用Matlab优化工具箱求解旅行商最短路径问题
- java io复用_学习Java编程-IO复用
- ibm+x3650+m4+linux+raid驱动,IBM X3650M4阵列卡驱动下载
- 浏览器加载js的阻塞与非阻塞
- python安装pyqt5 qml_用 PyQt5 和 QML 做了个小工具,,感觉 PyQt 和 QML 的交互比较繁琐...
- python如何读取文本_python 如何读取windows-1252格式文本?
- Struts2 初探
- 《跨越鸿沟》中的提到的五类用户
- AtCoder ABC237题解
- View的测量规则以及三大方法流程
- JSP基础 mcv规范 EL
- 最新微信公众号文章数据导出软件工具
- IOS开发插件和工具总结
- java存储张三李四_JAVA_day14_面向对象的特征
- Programming C#.Classes and Objects.传递参数
- Java多线程-实现Callable接口的call()方法,示例
- 2021年T电梯修理考试报名及T电梯修理考试试卷
- “希希敬敬对”队软件工程第九次作业-beta冲刺第七次随笔