美文网首页
获取RecyclerView已经滚动的百分比技巧

获取RecyclerView已经滚动的百分比技巧

作者: haegyeong | 来源:发表于2020-03-14 16:21 被阅读0次
  //当前RcyclerView显示区域的高度。水平列表屏幕从左侧到右侧显示范围
 int extent = recyclerView.computeHorizontalScrollExtent();
 //整体的高度,注意是整体,包括在显示区域之外的
 int range = recyclerView.computeHorizontalScrollRange();
//已经向下滚动的距离,为0时表示已处于顶部
 int offset = recyclerView.computeHorizontalScrollOffset();
//已经滚动的百分比 [0.0-1.0]
 float percentage = (offset / (float)(range - extent));

相关文章

网友评论

      本文标题:获取RecyclerView已经滚动的百分比技巧

      本文链接:https://www.haomeiwen.com/subject/sqxqpctx.html