title: Making StaggeredGridLayout wrap content
body: <p>I need to display a staggered grid within a linear layout.</p>
  
  <p><img src="https://i.stack.imgur.com/GNit8.png" alt="enter image description here"></p>
  
  <p>For that I have used a <code>StaggeredGridLayoutManager</code> on a <code>RecyclerView</code> from <code>android.support.v7.widget</code>. The problem is that <code>StaggeredGridLayoutManager</code> doesn't support <code>wrap_content</code>.</p>
  
  <p>There are other questions addressing the issue, but they are concerned with linear layouts, not staggered grids: </p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/27768495/not-able-to-add-empty-view-below-recyclerview">Not able to add empty view below Recyclerview</a></li>
  <li><a href="https://stackoverflow.com/questions/27475178/how-do-i-make-wrap-content-work-on-a-recyclerview">How do I make WRAP_CONTENT work on a RecyclerView</a></li>
  </ul>
  
  <p>As far as I understand I could derive <code>StaggeredGridLayoutManager</code> and implement <code>onMeasure</code>. Is there a way do to that without recalculating the positions and sizes of the children myself? When looking at the <a href="https://github.com/android/platform_frameworks_support/blob/master/v7/recyclerview/src/android/support/v7/widget/StaggeredGridLayoutManager.java" rel="nofollow noreferrer">StaggeredGridLayoutManager.java source</a>, I can see that it uses <code>ScrollbarHelper</code> to approximate the size of the scrolling content. Is there a way to reuse that?</p>