3

Currently I am using a RecyclerView with a LinearLayout Manager and an EditText as HeaderView for filtering the content of the list.

I would like to hide the EditText if the content of the RecyclerView is smaller than the RecyclerView itself.

Is there any way to "ask" the Recyclerview or the LayoutManager if its content can scroll?

Thank you all.

Andrew Thompson
  • 163,965
  • 36
  • 203
  • 405
Leonardo Medori
  • 341
  • 2
  • 9

3 Answers3

4

RecyclerView can't scroll anymore when the item at last position is completely visible.

In condition that would sound as:

mRecyclerView.getLayoutManager().findLastCompletelyVisibleItemPosition() == mRecyclerViewAdapter.getItemCount() - 1;
Nikola Despotoski
  • 46,951
  • 13
  • 114
  • 146
  • make sure, that `layout_height` is set to `match_parent`, otherwise, you will get a different height (initial default height), and therefore a different number for the last visible element. – Javatar Feb 16 '17 at 17:22
1

An answer that also accounts for dynamic screen sizes.

mRecyclerView.getViewTreeObserver().addOnScrollChangedListener(() -> {

    if (mRecyclerView.canScrollVertically(1) && //still scrolling
        mRecyclerView.computeVerticalScrollRange() >= mRecyclerView.getHeight()) { //Big enough for scrolling

        return;  //we still scrolling so early out.
        }

    DoMyFunction();
}
CloudyGoat
  • 41
  • 4
0

do you mean this:

https://developer.android.com/reference/android/support/v7/widget/RecyclerView.LayoutManager.html#canScrollVertically()

if(recyclerView.getLayoutManager().canScrollVertically()){
    // do stuff
} else{
    // do other stuff
}
Budius
  • 37,587
  • 15
  • 92
  • 134