0

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()
        }
    }
Muraino
  • 554
  • 7
  • 18
  • 1
    This https://stackoverflow.com/a/37606211/10248593 may help you. – Jinal Patel Apr 12 '22 at 12:14
  • private fun setupScrollListener() { scrollContainer.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { view, _, scrollY, _, _ -> if (view.getChildAt(0).bottom <= scrollContainer.height + scrollY) { View.hide() }else{ connectedDevicesCountBanner }) } I solved with this.. – Muraino Apr 12 '22 at 12:39

2 Answers2

0

This solved the problem

    private fun setupScrollListener() {
    scrollContainer.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { view, _, scrollY, _, _ ->
        if (view.getChildAt(0).bottom <= scrollContainer.height + scrollY) {
           //at bottom
        }else{
          
        }
    })
}
Muraino
  • 554
  • 7
  • 18
0

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  
            }          
    }
});
Sandesh Khutal
  • 1,712
  • 1
  • 4
  • 17