Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to detect the end of scroll event [duplicate]

I want to detect the end of scroll event of a scrollView. first,i implement the OnCrollChange method and i try to listen some values if they can help me to know the end of scroll. Thank to help me.

 scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener(){
            @Override
            public void onScrollChange(View view, int i, int i1, int i2, int i3){
                Toast.makeText(getApplicationContext(),"in SCroll ------->"+i+" "+i1+" "+i2+" "+i3,Toast.LENGTH_SHORT).show();
                shadowView.setBackgroundResource(R.drawable.shadow);
                if ((i3==0)){
                    Toast.makeText(getApplicationContext()," equality ----------------------> ",Toast.LENGTH_SHORT).show();
                    shadowView.setBackgroundResource(R.drawable.trans);
                }
                else {
                   // Toast.makeText(getApplicationContext()," NO ----------------------> ",Toast.LENGTH_SHORT).show();
                }
            }

        });
like image 800
Boris Avatar asked Oct 18 '25 04:10

Boris


2 Answers

This will help

scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
    @Override
    public void onScrollChanged() {
        if (scrollView != null) {
            if (scrollView.getChildAt(0).getBottom() <= (scrollView.getHeight() + scrollView.getScrollY())) {
                //scroll view is at bottom
            } else {
                //scroll view is not at bottom
            }
        }
    }
});
like image 174
Viswanath Kumar Sandu Avatar answered Oct 20 '25 17:10

Viswanath Kumar Sandu


Modify your onScrollChanged method as below

       @Override
        public void onScrollChanged(View view, int i, int i1, int i2, int i3){
            View view = (View) getChildAt(getChildCount()-1);
            int delta = (view.getBottom()-(getHeight()+getScrollY()));
            if(delta == 0){
                // You have reached bottom of the scroll view
            }
        }
like image 45
Krishna Sharma Avatar answered Oct 20 '25 17:10

Krishna Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!