gpt4 book ai didi

Android计算滚动recyclerView的百分比

转载 作者:太空宇宙 更新时间:2023-11-03 11:46:46 25 4
gpt4 key购买 nike

我试图通过这段代码自动显示滚动到 recylerview 项目末尾的百分比:

visibleItemCount = bookContentLayoutManager.getChildCount();
totalItemCount = bookContentLayoutManager.getItemCount();
firstVisibleItem = bookContentLayoutManager.findFirstVisibleItemPosition();

float percentage = (visibleItemCount * 100 / totalItemCount);
Log.e("percent ", percentage + "");

但它不正确,我正在尝试找到解决方案,这意味着显示当前滚动的 recyclerview 项目的百分比

最佳答案

Recyclerview 提供了以下垂直和水平滚动的方法,使用下面的代码,

        int offset = recyclerView.computeVerticalScrollOffset();
int extent = recyclerView.computeVerticalScrollExtent();
int range = recyclerView.computeVerticalScrollRange();

float percentage = (100.0f * offset / (float)(range - extent));

关于Android计算滚动recyclerView的百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46659744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com