Set setOnScrollChangeListener in the NestedScrollView parameters to get
- NestedScrollView v (scroll parent)
- int scrollY
- int oldScrollY
To determine if the offset is at the bottom, you need to get the content height value v.getChildAt(0).getMeasuredHeight() and compare the current scroll by the height of the parent element, if you have the same value, it means that it has reached the end.
You can get the height using the parent view with v.getMeasuredHeight()
NestedScrollView scroller = (NestedScrollView) findViewById(R.id.myScroll); if (scroller != null) { scroller.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { @Override public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { if (scrollY > oldScrollY) { Log.i(TAG, "Scroll DOWN"); } if (scrollY < oldScrollY) { Log.i(TAG, "Scroll UP"); } if (scrollY == 0) { Log.i(TAG, "TOP SCROLL"); } if (scrollY == ( v.getMeasuredHeight() - v.getChildAt(0).getMeasuredHeight() )) { Log.i(TAG, "BOTTOM SCROLL"); } } }); }
Webserveis Jun 04 '16 at 12:10 2016-06-04 12:10
source share