Swiperefreshlayout's drop-down refresh distance is shorter, and there is no API to set the drop-down distance, but look at Swiperefreshlayout source, you will find an internal variable mdistancetotriggersync , this variable determines the drop-down distance that triggers the refresh. The code below shows how to assign a value to the variable in the source:
Final Displaymetrics metrics =(int) math.min ((View) getParent ()). GetHeight () * Max_swipe_distance_ FACTOR, refresh_trigger_distance * metrics.density);
The above uses the parent view height and some constant calculations to determine the trigger distance. Max_swipe_distance_factor (0.6) and refresh_trigger_distance (120) are private constants that we cannot modify directly. However, we can recalculate the value of mdistancetotriggersync by means of reflection, the code is as follows:
Viewtreeobserver vto =swipelayout.getviewtreeobserver (); Vto.addongloballayoutlistener (NewViewtreeobserver.ongloballayoutlistener () { Public voidongloballayout () {FinalDisplaymetrics metrics =getresources (). Getdisplaymetrics (); Float Mdistancetotriggersync= Math.min ((View) swipelayout.getparent ()). GetHeight () * 0.6f, 500 *metrics.density); Try{Field field= Swiperefreshlayout.class. Getdeclaredfield ("Mdistancetotriggersync"); Field.setaccessible (true); Field.setfloat (Swipelayout, Mdistancetotriggersync); } Catch(Exception e) {e.printstacktrace (); } viewtreeobserver Obs=Swipelayout.getviewtreeobserver (); Obs.removeongloballayoutlistener ( This); }});
Compare the code, just change the value of refresh_trigger_distance (120) to 500, you will find that the drop-down refresh distance significantly increased, another code download: Swiperefreshlayout.rar