title: Android: How to have a 1 - 2 - 1 list item formation in a GridView or RecyclerView?
body: <p>I'm trying to achieve the following list item formation within a recycler or grid view:</p>
  
  <pre><code> 1
  1 1
   1
  1 1
   1
  </code></pre>
  
  <p>where <code>1</code> is a single view holder (list item). My list items all have the same width and height.</p>
  
  <p>I've attempted to use a recyclerview with a grid layout manager as seen here:</p>
  
  <pre><code>recyclerView.setLayoutManager(new GridLayoutManager(getContext(),2));
  </code></pre>
  
  <p>But this will strictly display 2 columns. </p>
  
  <p>I've tried using a <code>StaggeredGridLayoutManager</code> also with my <code>recyclerView</code> as seen below:</p>
  
  <pre><code>StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
  </code></pre>
  
  <p>But this only stretches my list items to fit a 2 column list, similar to the <code>GridLayoutManager</code>.
  I've also tried to change the width of 1 in 3 list views in my adapter, but the width of one view does not effect the position of another.</p>
  
  <p>The current setup looks like this:</p>
  
  <pre><code>    adapterPre = new CategoryListAdapter(this, getContext(),GeneralUtils.isLoggedIn());
      RecyclerView premadeLists = view.findViewById(R.id.practise_recycler);
      GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(),2);
      gridLayoutManager.setSpanSizeLookup(new CustomSpanSizeLookup());
      premadeLists.setLayoutManager(gridLayoutManager);
      premadeLists.setHasFixedSize(false);
      premadeLists.setAdapter(adapterPre);
  </code></pre>
  
  <p><code>CustomSpanSizeLookup</code>:</p>
  
  <pre><code>class CustomSpanSizeLookup extends GridLayoutManager.SpanSizeLookup {
      @Override
      public int getSpanSize(int position) {
          return position % 2 == 0 ? 2 : 1;
      }
  }
  </code></pre>