Inherit the listview, override the Overscrollby method, call the Super.overscrollby () method, replace the maxoverscrolly parameter
ImportAndroid.content.Context; ImportAndroid.util.AttributeSet; ImportAndroid.util.DisplayMetrics; ImportAndroid.widget.ListView; /*** Elastic listview. * @authorE*/ Public classFlexilistviewextendslistview{//Initial pull y-axis direction distance Private Static Final intmax_y_overscroll_distance = 100; //Contextual Environment PrivateContext Mcontext; //the distance on the y-axis can actually be pulled up and down Private intmmaxyoverscrolldistance; PublicFlexilistview (Context context) {Super(context); Mcontext=context; Initbouncelistview (); } PublicFlexilistview (Context context, AttributeSet attrs) {Super(context, attrs); Mcontext=context; Initbouncelistview (); } PublicFlexilistview (context context, AttributeSet attrs,intDefstyle) { Super(context, attrs, Defstyle); Mcontext=context; Initbouncelistview (); } Private voidInitbouncelistview () {FinalDisplaymetrics metrics =mcontext.getresources (). Getdisplaymetrics (); Final floatDensity =metrics.density; Mmaxyoverscrolldistance= (int) (Density *max_y_overscroll_distance); } @Overrideprotected BooleanOverscrollby (intDeltaX,intDeltaY,intSCROLLX,intScrolly,intScrollrangex,intScrollrangey,intMAXOVERSCROLLX,intMaxoverscrolly,Booleanistouchevent) { //The essence of implementation is to dynamically change the value of the maxoverscrolly here . return Super. Overscrollby (DeltaX, DeltaY, Scrollx, scrolly, Scrollrangex, Scrollrangey, MAXOVERSCROLLX, Mmaxyoverscrolldistance, istouchevent); } }
Android's ListView Bounce Effect