title: iOS like over scroll effect on Android
body: <p>I want to implement the iOS-like bounce overscroll effect in my app.</p>
  
  <p>I came across this <a href="https://stackoverflow.com/a/13391248/3500826">link</a> which suggests creating a custom <code>ScrollView</code>. But the problem is that when I am scrolling up and down fast it's working fine but as soon as I pull the bottom or top of the screen it's just stuck and the effect is not working anymore. </p>
  
  <p>As an example of the kind of animation I want to achieve you can look at this:</p>
  
  <p><img src="https://github.com/chthai64/overscroll-bouncy-android/raw/master/arts/OverscrollDemo.gif" alt=""></p>
  
  <p>This is the code I currently have:</p>
  
  <pre><code>public class ObservableScrollView extends ScrollView
  {
      private static final int MAX_Y_OVERSCROLL_DISTANCE = 150;
  
      private Context mContext;
      private int mMaxYOverscrollDistance;
  
      public ObservableScrollView(Context context)
      {
          super(context);
          mContext = context;
          initBounceScrollView();
      }
  
      public ObservableScrollView(Context context, AttributeSet attrs)
      {
          super(context, attrs);
          mContext = context;
          initBounceScrollView();
      }
  
      public ObservableScrollView(Context context, AttributeSet attrs, int defStyle)
      {
          super(context, attrs, defStyle);
          mContext = context;
          initBounceScrollView();
      }
  
      private void initBounceScrollView()
      {
          //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 = mContext.getResources().getDisplayMetrics();
          final float density = metrics.density;
  
          mMaxYOverscrollDistance = (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 mMaxYOverscrollDistance;
          return super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, maxOverScrollX, mMaxYOverscrollDistance, isTouchEvent);
      }
  }
  </code></pre>