Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Check if NestedScrollView is at the bottom or at the top

I am using a NestedScrollView and I want to check if the NestedScrollView is at the bottom or at the top :-)

Any suggestions? Thank you!

like image 765
FabASP Avatar asked Aug 29 '15 16:08

FabASP


2 Answers

ViewCompat.canScrollVertically(target, -1);
like image 61

Create a SetOnScrollChangeListener

BottomSheet.SetOnScrollChangeListener(this);

The inside of the listener interface

  public void OnScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY)
    {
        if (scrollY == 0)
        {
            //Do something here when ur scroll reached the bottom by scrolling up
        }

        if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight()))
        {
            //Do something here when ur scroll reached top by scrolling down
        }
    }
like image 35
Andreas Constantinou Avatar answered Oct 08 '22 12:10

Andreas Constantinou