title: RecyclerView items with different heights with FlexboxLayoutManager
body: <p><strong>How can I display my recycleview items in a row while keeping their original height?</strong></p>
  
  <p>I want to use a recycleviewer with FlexboxLayoutManager.
  Every item normally having their own height depending on their content.
  However, every recycleview item on the same row always ending up with an equal height somehow.</p>
  
  <p>How can I display my recycleview items in a row while respecting their original height?</p>
  
  <p><strong>I need the items to be displayed like this:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/x5oMe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x5oMe.png" alt="Correct one"></a></p>
  
  <p><strong>What I tried without success:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/LhE5j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LhE5j.png" alt="Fault one"></a>
  (The small items always stretches)</p>
  
  <p><strong>My code where I set the layout manager:</strong></p>
  
  <pre><code>        adapter = new ProductAdapter(getContext(), productsList);
  
          layoutManager.setFlexWrap(FlexWrap.WRAP);
          layoutManager.setFlexDirection(FlexDirection.ROW);
         // layoutManager.setAlignContent(AlignContent.CENTER);
  
          recyclerView.setLayoutManager(layoutManager);
          recyclerView.setAdapter(adapter);
  </code></pre>
  
  <p>I have tried this <code>layoutManager.setAlignContent(AlignContent.CENTER);</code> 
  However you can't set <code>alignContent</code> in a <code>FlexboxLayoutManager</code> for a recycleviewer.
  The app crash because <code>alignContent</code> is for <code>FlexboxLayout</code> (not manager).  </p>
  
  <p><strong>EDITED:</strong>
  When using a <code>StaggeredGridLayoutManager</code> , this will solve the problem.
  However you will lose the responsive behaviour of the FlexboxLayoutManager.</p>
  
  <p>I created my own responsive behaviour for a StaggeredGridLayoutManager:</p>
  
  <pre><code> DisplayMetrics displayMetrics = getActivity().getResources().getDisplayMetrics();
          float dpWidth = displayMetrics.widthPixels / displayMetrics.density;
          int spanCount = (int) (dpWidth / 222);  // 222=total space for 1 item incl. margin
  
              recyclerView.setLayoutManager(new StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL));
  </code></pre>