Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android calculate percentage of scrolling recyclerView

Tags:

android

i'm trying to show percentage of scrolling automatically to end of recylerview item by this code:

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

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

but it doesn't correct and i'm trying to find whats is solution of that, it means show percentage of current scrolled recyclerview items

like image 664
DolDurma Avatar asked Oct 10 '17 06:10

DolDurma


1 Answers

Recyclerview provides the following methods for vertical and horizontal scroll use the below code,

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

        float percentage = (100.0f * offset / (float)(range - extent));
like image 80
Mightian Avatar answered Oct 10 '22 08:10

Mightian