public class BounceListView extends ListView { private int maxYOverscroll; private static final float MAX_Y_OVERSCROLL_DISTANCE = 200; public BounceListView(Context context) { super(context); initBounceListView(); } public BounceListView(Context context, AttributeSet attrs) { super(context, attrs); initBounceListView(); } public BounceListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); initBounceListView(); } private void initBounceListView() { //get the density of the screen and do some maths with it on the max overscroll distance //variable so that you get similar behaviors no matter what the screen size final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); final float density = metrics.density; maxYOverscroll = (int) (density * MAX_Y_OVERSCROLL_DISTANCE); } @Override protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) { //This is where the magic happens, we have replaced the incoming maxOverScrollY with our own custom variable maxYOverscroll; return super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, maxOverScrollX, maxYOverscroll, isTouchEvent); }
Source: https://habr.com/ru/post/137098/