title: RecyclerView Children count smaller than the number of children
body: <p>I have a very strange problem today: I have a RecyclerView that shows some thumbnails horizontally, I use an <code>smoothScrollToPosition</code> to navigate to the item I need, but I noticed a problem: it will not scroll to the last item. Upon further debugging, I found that my recyclerview has less children than it displays! I see five items, with 3 displayed at a time. but the children count (gotten with <code>recyclerView.getChildCount</code>) returns 4 instead of five, and I can't get the last child with <code>getChildAt(4)</code>. Even more strange, the <code>adapter.getItemCount()</code> returns 5, and <code>recyclerView.getAdapter().getItemCount()</code> returns 5...</p>
  
  <p>Upon inspecting the <code>layoutAdapter</code>, <code>recyclerView.getLayoutManager().getItemCount()</code> returns 5, and `recyclerView..getLayoutManager().getChildCount() returns 4...</p>
  
  <p><strong>I need two things</strong>: First, I need my recyclerView to scroll to that last item, and Second: I need to be able to get all children, since I do some modifications on them as the user interact with the items.</p>
  
  <p>Some code:</p>
  
  <pre><code>// Scrolling and editing the item inside the recyclerView
  // It doesn't scroll to position 4, even having a item there...
  mLayoutManager.smoothScrollToPosition(recyclerView, null, position);
  
  // the code bellow returns null if position = 4, even if the recyclerView adapter has a item at index 4, and it is visible...
  ImageView iv = (ImageView) recyclerView.getChildAt(position);
  if (iv != null) {
      iv.setPadding(10, 10, 10, 10);
      iv.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));
      ImageView ivo = (ImageView) recyclerView.getChildAt(position - 1);
      if (position - 1 == 0) {
          ivo.setPadding(10, 10, 10, 10);
      } else {
          ivo.setPadding(0, 10, 10, 10);
      }
      ivo.setBackgroundColor(getResources().getColor(R.color.transparent));
  }
  </code></pre>
  
  <p>smoothScrollToPosition implementation:</p>
  
  <pre><code>public class SnappingLinearLayoutManager extends LinearLayoutManager {
  
      private static final float MILLISECONDS_PER_INCH = 150f;
  
      public SnappingLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
          super(context, orientation, reverseLayout);
      }
  
      @Override
      public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state,
                                         int position) {
          RecyclerView.SmoothScroller smoothScroller = new TopSnappedSmoothScroller(recyclerView.getContext()){
              @Override
              public PointF computeScrollVectorForPosition(int targetPosition) {
                  return new PointF(0, 1);
              }
  
              //This returns the milliseconds it takes to scroll one pixel.
              @Override
              protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
                  return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
              }
          };
          smoothScroller.setTargetPosition(position);
          startSmoothScroll(smoothScroller);
      }
  
      private class TopSnappedSmoothScroller extends LinearSmoothScroller {
          public TopSnappedSmoothScroller(Context context) {
              super(context);
  
          }
  
          @Override
          public PointF computeScrollVectorForPosition(int targetPosition) {
              return SnappingLinearLayoutManager.this
                      .computeScrollVectorForPosition(targetPosition);
          }
  
          @Override
          protected int getVerticalSnapPreference() {
              return SNAP_TO_ANY;
          }
      }
  }
  </code></pre>