title: gridView with different cells sizes, pinterest style
body: <h2>Background</h2>
  
  <p><a href="http://developer.android.com/reference/android/widget/GridView.html" rel="noreferrer"><strong>GridView</strong></a> is a class that extends <a href="http://developer.android.com/reference/android/widget/AdapterView.html" rel="noreferrer">AdapterView</a> , which means it shows cells in a grid-style efficiently, recycling old views to be shown as new ones when the user scrolls it.</p>
  
  <h2>The problem</h2>
  
  <p>Sometimes, you would want to get a special UI, which resembles the Windows Phone Tiles UI, having cells of different sizes on top of each other.</p>
  
  <p>Something like this:</p>
  
  <pre><code>AABB
  AACC
  AADD
  AADD
  </code></pre>
  
  <p>each letter represents a part of its cell, so cell A is 2x4 , cell B and cell C take 2x1 each , and cell D is 2x2 .</p>
  
  <p>It could be even more than that, where cell D finished a bit above what i've shown, and right beneath it there is another cell so the end of D and the end of A aren't necessary aligned.</p>
  
  <p>an example of an app that has this style is <a href="https://play.google.com/store/apps/details?id=com.pinterest" rel="noreferrer">pinterest</a> .</p>
  
  <p>GridView doesn't allow such a thing.</p>
  
  <p>In fact , every solution I've tried has issues. Would like to ask if there are any other alternatives or better solutions.</p>
  
  <h2>What I've found</h2>
  
  <p>There are multiple ways to handle this problem:</p>
  
  <ol>
  <li><p>As a class that extends <a href="http://developer.android.com/reference/android/widget/AdapterView.html" rel="noreferrer"><strong>AdapterView</strong></a> <strong>GridView</strong> has the ability to have a type for each item (using the <a href="http://developer.android.com/reference/android/widget/BaseAdapter.html#getItemViewType%28int%29" rel="noreferrer"><strong>BaseAdapter</strong></a>), which would allow you to set how to layout the cell . </p>
  
  <p>However, it still limits you since you will get rows of items, one beneath the other. you have to have them aligned.</p></li>
  <li><p><a href="http://developer.android.com/reference/android/widget/GridLayout.html" rel="noreferrer"><strong>GridLayout</strong></a> is a relatively new layout, and it's quite flexible. Google has published a nice compatibility library for it, supporing API7 and above.</p>
  
  <p>However, it doesn't use any recycling of views, so it's a bad choice in case you wish to show a lot of items.</p>
  
  <p>If you have a lot of items, you would need to create all of the views for them .</p></li>
  <li><p><a href="http://www.androidviews.net/2013/01/quiltview-library/" rel="noreferrer"><strong>QuiltView Library</strong></a> - extends from GridLayout, so basically has the same problem like it.</p></li>
  <li><p><a href="http://www.androidviews.net/2013/01/pinterest-like-adapterview/" rel="noreferrer"><strong>StaggeredGridView</strong></a>  - looks the most promising, but has a lot of bugs, especially when changing orientation. such bugs include empty cells, bad scrolling and NPEs (rare but still happens). I'm also not sure if it supports having customized cells instead of imageViews alone .</p></li>
  <li><p>other solutions, as mentions <a href="http://www.justinmccandless.com/blog/Pinterest-Style+Staggered+Masonry+List+in+Android" rel="noreferrer"><strong>here</strong></a> .</p></li>
  </ol>
  
  <h2>The question</h2>
  
  <p>Does anyone know of another alternative to this problem? Maybe some workarounds for any of the solutions I've shown?</p>
  
  <hr>
  
  <p>EDIT: I think that about StaggeredGridView , the scrolling and exceptions can be solved by using a normal ImageView that you set its size inside the getView. i think that the reason for it to work in a weird way is that the sample updates the size of the imageview after it was loaded from the internet. </p>
  
  <p>However, empty cells issue still remains in this library. not only that, but their sizes change a lot , even without changing the orientation.</p>
  
  <hr>
  
  <p>EDIT: for now, i think the best solution is to use ,  <a href="https://github.com/huewu/PinterestLikeAdapterView" rel="noreferrer"><strong>PinterestLikeAdapterView library</strong></a>. </p>
  
  <p>it doesn't have any issues that i can find. </p>
  
  <p>however, it can't make items to take more than 1 cell width. it's very good nevertheless.</p>
  
  <p>EDIT: sadly it has issues with notifyDataSetChanged . i've reported about it <a href="https://stackoverflow.com/questions/19243670/how-to-avoid-refreshing-of-cells-on-when-calling-notifydatasetchanged-for-pint"><strong>here</strong></a>.</p>