Created
November 19, 2014 08:45
-
-
Save umetsu/99f4aa342e27221770b4 to your computer and use it in GitHub Desktop.
This file contains 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 characters
package net.prunusumume.sample.views; | |
import android.content.Context; | |
import android.util.AttributeSet; | |
import android.view.ViewGroup; | |
import android.widget.GridView; | |
/** | |
* ScrollViewに入れても2行以上表示することができるGridView | |
* http://stackoverflow.com/questions/8481844/gridview-height-gets-cut | |
*/ | |
public class ExpandableHeightGridView extends GridView { | |
private boolean mExpanded = false; | |
public ExpandableHeightGridView(final Context context) { | |
super(context); | |
} | |
public ExpandableHeightGridView(final Context context, final AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public ExpandableHeightGridView(final Context context, final AttributeSet attrs, final int defStyle) { | |
super(context, attrs, defStyle); | |
} | |
public boolean isExpanded() { | |
return mExpanded; | |
} | |
public void setExpanded(final boolean expanded) { | |
mExpanded = expanded; | |
} | |
@Override | |
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { | |
if (!isExpanded()) { | |
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | |
return; | |
} | |
final int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); | |
super.onMeasure(widthMeasureSpec, expandSpec); | |
final ViewGroup.LayoutParams params = getLayoutParams(); | |
params.height = getMeasuredHeight(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment