500px / greedo-layout-for-android

Full aspect ratio grid LayoutManager for Android's RecyclerView
MIT License
1.64k stars 156 forks source link

Is there a findLastVisibleItemPosition() method? #4

Closed alashow closed 8 years ago

alashow commented 8 years ago

How can i get last visible position? There is findFirstVisibleItemPosition() method, but no last visible position getter.

JVillella commented 8 years ago

Hey @alashow, we don't precompute the positions. As you scroll, it's laid out on the fly, and the size calculations are cached, and returned on subsequent calls. Because of this, we don't know the last visible position ahead of time. Is there something you are specifically wanting to achieve?

AngleV commented 8 years ago

@JVillella If you wish to implement an endless scroll listener you must know the LastVisibleItemPosition to make the necessary calculations. So is there any way to find out the last visible item ?

JVillella commented 8 years ago

Hey @AngleV, no you don't, at least not explicitly. Up to you in regards to the implementation specifics, but what we have done is wrap a RecyclerView.OnScrollListener within an RxJava PublishSubject. In it's onScrolled() we check if we are close to the edge using the total item count, the visible item count, and the first visible item index. If so, we notify the subscriber by via onNext(...).