implementation: Use the onscrollstatechanged callback to detect the scrolling state, and set a status value similar to isscrolling inside the recyclerviewadapter to control the loading of the network picture.
Here is a code example:
// Add the following code to the Baseadapter Public Abstract class Baserecyclerviewadapter<t> extends recyclerview.adapter<recyclerview.viewholder> { ... protected false ; ... Public void setscrolling (Boolean scrolling) { = scrolling; }}
Specific sub-adapter implementations:
//control in Onbind in sub-adapter Public classSubrecyclerviewadapter extends Baserecyclerviewadapter<dataguardranking>{... @Override Public voidOnbindviewholder (Recyclerview.viewholder Viewholder,intposition) {Recyclerviewholder Holder=(Recyclerviewholder) Viewholder; ...if(! Textutils.isempty (Data.getavatarurl ()) &&!isscrolling) { //Here you can load the library with glide and other network pictures .}Else{Holder.avatarImg.setImageResource (account for bitmap local resources); } super.onbindviewholder (holder, position); }}
To listen at the UI layer:
//external to Recyclerview Setup monitoringMrecyclerview.addonscrolllistener (NewRecyclerview.onscrolllistener () {@Override Public voidOnscrollstatechanged (Recyclerview Recyclerview,intnewstate) { //View Source There are three states of State: Scroll_state_idle (stationary), scroll_state_dragging (Ascent), scroll_state_settling (drop) if(newstate = = Scroll_state_idle) {//Load picture resources when scrolling at rest, greatly improving smoothnessMrecyclerviewadapter.setscrolling (false); Mrecyclerviewadapter.notifydatasetchanged (); //Onbindviewholder responds to the call after notify is called}Elsemrecyclerviewadapter.setscrolling (true); Super.onscrollstatechanged (Recyclerview, newstate); }}); Mrecyclerview.setadapter (Mrecyclerviewadapter) ;
Android scrolling Recyclerview when loading images with smoothness optimization