title: Snappy scrolling in RecyclerView
body: <p>I am trying to use the new <code>RecyclerView</code> class for a scenario where I want the component to snap to a specific element when scrolling (The old Android <code>Gallery</code> comes to mind as an example of such a list with a center-locked item). </p>
  
  <p>This is the approach that I am taking thus far:</p>
  
  <p>I have an interface, <code>ISnappyLayoutManager</code>, which contains a method, <code>getPositionForVelocity</code>, which calculates at which position the view should end the scrolling given the initial fling velocity.</p>
  
  <pre><code>public interface ISnappyLayoutManager {
      int getPositionForVelocity(int velocityX, int velocityY);  
  }
  </code></pre>
  
  <p>Then I have a class, <code>SnappyRecyclerView</code>, which subclasses <code>RecyclerView</code> and overrides its fling() method in such a manner as to fling the view the exact right amount:</p>
  
  <pre><code>public final class SnappyRecyclerView extends RecyclerView {
  
      /** other methods deleted **/
  
      @Override
      public boolean fling(int velocityX, int velocityY) {
          LayoutManager lm = getLayoutManager();
  
          if (lm instanceof ISnappyLayoutManager) {
              super.smoothScrollToPosition(((ISnappyLayoutManager) getLayoutManager())
                      .getPositionForVelocity(velocityX, velocityY));
          }
          return true;
      }
  }
  </code></pre>
  
  <p>I am not very happy with this approach for several reasons. First of all, it seems counter to the philosophy of the 'RecyclerView' to have to subclass it to implement a certain type of scrolling. Second, if I want to just use the default <code>LinearLayoutManager</code>, this becomes somewhat complex as I have to mess around with its internals in order to understand its current scroll state and calculate out exactly where this scrolls to. Finally, this doesn't even take care of all the possible scroll scenarios, as if you move the list and then pause and then lift a finger, no fling event occurs (the velocity is too low) and so the list remains in a halfway position. This can possibly be taken care of by adding an on scroll state listener to the <code>RecyclerView</code>, but that also feels very hacky.</p>
  
  <p>I feel like I must be missing something. Is there a better way to do this?</p>