title: RecyclerView/SnapHelper - How to set variable position of the cards so that they peek differently based on position
body: <p>I am new to android and hence RV and I am trying to achieve the layout where the first and last card are not centered and instead show more of the cards after and before them. Maybe at In this case I can see 16dp for the second cards and same thing for the penultimate card which makes the first and last card not centered.
  But 8dp each for the rest of the cards so the intermediate cards appear centered. Maybe using itemDecoration somehow for the 2nd and the penultimate card somehow.</p>
  
  <p><a href="https://i.stack.imgur.com/0VXho.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0VXho.png" alt="enter image description here"></a></p>
  
  <p>I was able to achieve showing parts of next and prev cards by following what is suggested here, but that only centers all the cards uniformly :
  <a href="https://stackoverflow.com/questions/51297250/how-to-show-part-of-next-previous-card-recyclerview">How to show part of next/previous card RecyclerView</a></p>
  
  <p>I tried overriding getItemOffsets but it gets triggered everytime I scroll to the first or the last card and moves the 2nd and 2nd to last card incorrectly 
  and also doesn't center them correctly when I scroll to them.</p>
  
  <pre><code>  public static class MyItemDecoration extends RecyclerView.ItemDecoration {
  
      @Override
      public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
  
        final int itemPosition = parent.getChildAdapterPosition(view);
        if (itemPosition == RecyclerView.NO_POSITION) {
          return;
        }
  
        final int itemCount = state.getItemCount();
        if (itemCount &gt; 0 &amp;&amp; itemPosition == 1) {
          outRect.left -= 16;
          outRect.right -= 16;
        }
  
        else if (itemCount &gt; 0 &amp;&amp; itemPosition == itemCount - 1) {
          outRect.left += 16;
          outRect.right += 16;
        }
      }
    }
  </code></pre>
  
  <p>RV Setup </p>
  
  <pre><code> SnapHelper snapHelper = new PagerSnapHelper();
          RecyclerView rv = getBinding().rv;
          rv.setOnFlingListener(null);
          snapHelper.attachToRecyclerView(rv);
  </code></pre>