前言
LinearSnapHelper与PagerSnapHelper是一个滑动自动回正的一个辅助类,一般多用于RecyclerView的滚轮选择器的开发上
LinearSnapHelper与PagerSnapHelper的区别, LinearSnapHelper多用于一页显示多行内容的线性列表,PagerSnapHelper用于当前只显示一页内容的翻页列表
转载请注明来源:https://www.cnblogs.com/guanxinjing/p/16276217.html
LinearSnapHelper的使用
效果图
设置LinearSnapHelper代码
val provinceLinearSnapHelper = LinearSnapHelper()
provinceLinearSnapHelper.attachToRecyclerView(mRecyclerView)
监听当前滚动的居中位置,注意是的居中位置
mRecyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { super.onScrollStateChanged(recyclerView, newState) if (newState == RecyclerView.SCROLL_STATE_IDLE) { if (recyclerView != null && recyclerView.childCount > 0) { provinceLinearSnapHelper.findSnapView(mBinding.province.layoutManager)?.let { val position = recyclerView.getChildAdapterPosition(it) } } } } })
PagerSnapHelper
设置代码
val pagerSnapHelper = PagerSnapHelper()
pagerSnapHelper.attachToRecyclerView(mBinding.province)
End
本文来自博客园,作者:观心静 ,转载请注明原文链接:https://www.cnblogs.com/guanxinjing/p/16276217.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效