i just want to detect the position of the scroll nestedscrollview android at the bottom, and the to call function. my code is :
scroll.getViewTreeObserver()
This worked for me :
nestedScroll.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (v.getChildAt(0).getBottom()<=(nestedScroll.getHeight()+scrollY)) {
System.out.println("End of NestedScrollView");
}
}
});
Basically , we add many views inside a nestedScrollView but wrap them together in a form of Single View. Therefore, childCount will always be 1 with its index 0. Thus, used v.getChildAt(0).getBottom()
to determine its bottom. Now, nestedScroll.getHeight()
returns height in pixel,and , scrollY
will return current vertical origin. Therefore, the above condition will be true everytime the bottom of NestedScrollView is reached.
if (v.getChildAt(0).getBottom()==(nestedScroll.getHeight()+nestedScroll.getScrollY()))
This only works some time... therefore, don't use it in such way.