'Android: How to detect when NestedScrollView scrolled to the bottom
I have tried some approach and since we have different screen size, I am not able to get a better way. Here is my code
private val scrollContainer
get() = View.findViewById<NestedScrollView>(R.id.scroll_container)
scrollContainer.setOnScrollChangeListener { _, _, newScrollY, _, oldScrollY ->
val length = 1.5
val deltaScrollY = newScrollY - oldScrollY
if (deltaScrollY > length) {
View.hide()
}
if (deltaScrollY < -length) {
View.show()
}
}
Solution 1:[1]
This solved the problem
private fun setupScrollListener() {
scrollContainer.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { view, _, scrollY, _, _ ->
if (view.getChildAt(0).bottom <= scrollContainer.height + scrollY) {
//at bottom
}else{
}
})
}
Solution 2:[2]
Try this
scroll.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
View view = (View) scroll.getChildAt(scroll.getChildCount() - 1);
int diff = (view.getBottom() - (scroll.getHeight() + scroll
.getScrollY()));
if (diff == 0) {
//your code
}
}
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Muraino |
| Solution 2 | Sandesh KhutalSaheb |
