code: private float calculateDx(float distanceX) {
      int currentX = view.getScrollX();
      float nextX = distanceX + currentX;
      boolean isInsideHorizontally = nextX >= minX && nextX <= maxX;
      return isInsideHorizontally ? distanceX : 0;
    }
docs: Returns the distance in the X axes to perform the scroll taking into account the view
  boundary.