How to trigger an event when scrollView reach the bottom with Android?

前端 未结 5 1006
情话喂你
情话喂你 2020-12-10 03:48

Im looking for an event that I can use on the scrollView to be fired when the user has scrolled to the bottom.

E.g my list of items should be extended with more item

5条回答
  •  甜味超标
    2020-12-10 04:02

    Don't try SetOnScrollChangeListener if you are working with android API below 21 (android M), you can try this :

    yourScrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
                @Override
                public void onScrollChanged() {
                    int rootHeight = yourScrollView.getHeight();
                    int childHeight = yourScrollView.getChildAt(0).getHeight();
                    int scrollY = yourScrollView.getScrollY();
                    if(childHeight - rootHeight == scrollY)
                    Log.d("Hei","You Have Reach The End!");
                }
            });
    

提交回复
热议问题