how to detect the position of the scroll nestedscrollview android at the bottom?

后端 未结 7 984
不知归路
不知归路 2020-12-04 22:19

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()
         


        
7条回答
  •  -上瘾入骨i
    2020-12-04 22:25

    for api <23 you can add a treeObserver.scrollChangeLister store a local float variable and check which way your scrolling like this

    example

    public class About extends AppCompatActivity implements 
    ViewTreeObserver.OnScrollChangedListener{
    
    private float viewScrolled = 0;
    
       nestedScrollView.getViewTreeObserver().addOnScrollChangedListener(this);
    
    }
    
    @Override
    public void onScrollChanged() {
    
        if (viewScrolled < nestedScrollView.getScrollY()){
            viewScrolled = nestedScrollView.getScrollY();
            Log.d(TAG, "scrolling up");
        }
        if (viewScrolled > nestedScrollView.getScrollY()){
            viewScrolled = nestedScrollView.getScrollY();
            Log.d(TAG, "scrolling down");
        }
    }
    

提交回复
热议问题