Created
March 26, 2014 11:57
Revisions
-
runemart created this gist
Mar 26, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ // http://www.jayway.com/2012/10/04/how-to-make-the-height-of-a-gridview-wrap-its-content/ public class WrappingGridView extends GridView { public WrappingGridView(Context context) { super(context); } public WrappingGridView(Context context, AttributeSet attrs) { super(context, attrs); } public WrappingGridView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int heightSpec = heightMeasureSpec; if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) { // The great Android "hackatlon", the love, the magic. // The two leftmost bits in the height measure spec have // a special meaning, hence we can't use them to describe height. heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); } super.onMeasure(widthMeasureSpec, heightSpec); } }