当前位置: 首页 > news >正文

记录跟随recyclerview滑动的指示器

老早之前做的一个功能,横向recyclerview滑动时,底部做跟随滑动指示器。今天代码不用了,记录下代码。

<LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="@dimen/fourteen"android:orientation="vertical"android:paddingLeft="@dimen/sixteen"android:paddingRight="@dimen/sixteen"><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/rv_teacher"android:layout_width="match_parent"android:layout_height="wrap_content"></androidx.recyclerview.widget.RecyclerView><RelativeLayoutandroid:id="@+id/scroll_bar_bg"android:layout_width="30dp"android:layout_height="4dp"android:layout_gravity="center"android:layout_marginTop="@dimen/six"android:background="@drawable/bg_fast_view"><Viewandroid:id="@+id/scroll_bar"android:layout_width="20dp"android:layout_height="4dp"android:layout_centerVertical="true"android:background="@drawable/bg_scroll_bar" /></RelativeLayout></LinearLayout>

bg_fast_view

<shape xmlns:android="http://schemas.android.com/apk/res/android"><solidandroid:color="@color/Gray"/><cornersandroid:radius="@dimen/ten"/></shape>

bg_scroll_bar

<shape xmlns:android="http://schemas.android.com/apk/res/android"><solidandroid:color="@color/title_bg"/><cornersandroid:radius="@dimen/ten"/></shape>
RelativeLayout scrollBarBg = view.findViewById(R.id.parent_layout);
View scrollBar = view.findViewById(R.id.main_line);GridLayoutManager layoutManager = new GridLayoutManager(mContext, 2);layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);rvTeacher.setLayoutManager(layoutManager);teacherAdapter = new RecommendTeacherRVAdapter(mContext);rvTeacher.setAdapter(teacherAdapter);rvTeacher.addOnScrollListener(new RecyclerView.OnScrollListener() {public int range = 0;@Overridepublic void onScrollStateChanged(RecyclerView recyclerView, int newState) {super.onScrollStateChanged(recyclerView, newState);}@Overridepublic void onScrolled(RecyclerView recyclerView, int dx, int dy) {super.onScrolled(recyclerView, dx, dy);//整体的总宽度,注意是整体,包括在显示区域之外的。int temp = recyclerView.computeHorizontalScrollRange();if (temp > range) {range = temp;}int offset = recyclerView.computeHorizontalScrollOffset();int extent = recyclerView.computeHorizontalScrollExtent();float proportion = (float) (offset * 1.0 / (range - extent));//计算滚动条宽度float transMaxRange = scrollBarBg.getWidth() - scrollBar.getWidth();//设置滚动条移动scrollBar.setTranslationX(transMaxRange * proportion);}});


文章转载自:
http://boxer.ciuzn.cn
http://charlatanry.ciuzn.cn
http://bulletproof.ciuzn.cn
http://biomedicine.ciuzn.cn
http://body.ciuzn.cn
http://chicquest.ciuzn.cn
http://amplification.ciuzn.cn
http://birdcage.ciuzn.cn
http://carola.ciuzn.cn
http://baiao.ciuzn.cn
http://bey.ciuzn.cn
http://angelica.ciuzn.cn
http://catlick.ciuzn.cn
http://ataxia.ciuzn.cn
http://bidialectalism.ciuzn.cn
http://cavelike.ciuzn.cn
http://biohazard.ciuzn.cn
http://blaspheme.ciuzn.cn
http://calamus.ciuzn.cn
http://blinkard.ciuzn.cn
http://cali.ciuzn.cn
http://bendy.ciuzn.cn
http://abiogenesis.ciuzn.cn
http://chartometer.ciuzn.cn
http://antineutron.ciuzn.cn
http://antebellum.ciuzn.cn
http://autarch.ciuzn.cn
http://capitalism.ciuzn.cn
http://baragnosis.ciuzn.cn
http://cher.ciuzn.cn
http://www.dtcms.com/a/271253.html

相关文章:

  • 智能避让+自动换针:三坐标让汽车检具测量安全又高效
  • 小鹏汽车6月交付车辆34,611辆,同比增长224%
  • 实现子系统深度融合,IBMS系统消除信息孤岛释放价值潜力
  • 云成本优化的核心原则与框架
  • React 编译器与性能优化:告别手动 Memoization
  • App中分发中的防盗链开发是做什么的?
  • 米思齐2.0 3.0 mixly arduino 编程软件下载安装及详情使用指南 导入库文件方法 支持8266 esp32
  • # 如何让微软 Edge 浏览器以 IE 模式打开某些网站?
  • APP上架怎么避免麻烦应对解决方案和替代方案
  • Spring State Machine
  • git上传大文件启用LFS git报错 the remote end hung up unexpectedly
  • 数学建模:非线性规划:二次规划问题
  • 项目管理进阶——解读智能制造项目PMO规划与项目管理方案【附全文阅读】
  • 软件测试报告第三方是什么?软件测试报告都包含啥?
  • 理解死锁:场景、实例与预防策略
  • JavaScript数组方法——梳理和考点
  • 20-C#构造函数--虚方法
  • 深度学习11(调参设参+批标准化)
  • tomcat设置预防host头攻击
  • 使用octomap将pcd点云地图转化为八叉树地图和占据栅格地图
  • MCP快速入门—快速构建自己的服务器
  • 龙虎榜——20250709
  • OpenAI 推出其 AI 代理框架的四项关键更新
  • Python数据分析案例|从模拟数据到可视化:零售门店客流量差异分析全流程
  • 拼多多正在错失即时零售?
  • C++智能指针与Qt内存管理详解
  • RESTful接口设计规范详解
  • SAP采购管理系统替代选谁?8Manage SRM全面优势测评与深度对比
  • 码云创建分支
  • 网络请求与现实生活:用办理业务类比理解HTTP通信