Mrecycleview.setonscrolllistener (NewRecyclerview.onscrolllistener () {//used to mark whether a slide is being made to the last, whether it is sliding down BooleanIsslidingtolast =false; @Override Public voidOnscrollstatechanged (Recyclerview Recyclerview,intnewstate) {Staggeredgridlayoutmanager Manager=(Staggeredgridlayoutmanager) Recyclerview.getlayoutmanager (); //When you do not scroll if(NewState = =recyclerview.scroll_state_idle) { //gets the last fully displayed itemposition int[] lastvisiblepositions = Manager.findlastvisibleitempositions (New int[Manager.getspancount ()]); intLastvisiblepos =Getmaxelem (lastvisiblepositions); intTotalitemcount =Manager.getitemcount (); //determine if scrolling to the bottom if(Lastvisiblepos = = (totalItemCount-1) &&isslidingtolast) { //load more-functional codeLN.E ("Howes right=" +manager.findlastcompletelyvisibleitemposition ()); Toast.maketext (Getactivitycontext (),"Load More", 0). Show (); } }} @Override Public voidOnscrolled (Recyclerview Recyclerview,intDxintdy) { Super. onscrolled (recyclerview, DX, dy); //DX is used to determine the direction of transverse sliding, dy is used to determine the longitudinal direction if(Dy > 0){ //greater than 0 indicates that scrolling downIsslidingtolast =true; }Else{ //less than or equal to 0 means stop or scroll upIsslidingtolast =false; } }});
Private int getmaxelem (int[] arr) { int size = arr.length; int maxval = integer.min_value; for (int i = 0; i < size; i++) { if (arr[i]>maxval) = arr[i ]; } return maxval;}
Android Recyclerview Waterfall Stream swipe to last automatically load more