Search code examples
androidandroid-layoutandroid-recyclerviewlinearlayoutmanager

RecyclerView inaccurate first completely visible item index if clipToPadding="false"


i have a RecyclerView with top padding and android:clipToPadding="false"

when findFirstCompletelyVisibleItemPosition() is called on the RecyclerView's LinearLayoutManager, it returns the index of the first item that would be completely visible if android:clipToPadding were set to true.

Any idea how to get the first actually completely visible item index if android:clipToPadding is set to false?


Solution

  • i couldn't get it to work with LinearLayoutManager#findFirstCompletelyVisibleItemPosition(), but i figured out another solution.

    Since I just needed to know how much the RecyclerView's top was offset, i used RecyclerView#computeVerticalScrollOffset(). Even though computeVerticalScrollOffset() estimates how much scrollable space is left, since i just needed to know how much was offset close to the top, it's good enough