How to find percentage of each visible item in recycleview

后端 未结 4 1818
忘了有多久
忘了有多久 2020-12-31 20:15
int findFirstVisibleItemPosition();
int findFirstCompletelyVisibleItemPosition();
int findLastVisibleItemPosition();
int findLastCompletelyVisibleItemPosition();
         


        
4条回答
  •  醉话见心
    2020-12-31 20:16

    You need to write addOnScrollListener() for recyclerview and inside that write following code where you will get position of firstVisibleItem and then you can get dimension of that item on each scroll. Just save previous dimension in global variable and compare it with the current dimension and calculate percentage on every scroll change. When you get your desired percentage then perform your operations.

    int position = linearLayoutManager.findFirstVisibleItemPosition();
    Rect rect = new Rect();
    linearLayoutManager.findViewByPosition(position).getGlobalVisibleRect(rect);
    

提交回复
热议问题