Reputation: 857
I have my gridView in a layout contained in a scrollView, so I want to make gridView show all its items. I already use android:layout_height="wrap_content"
but it still makes it scrollable.
my grid item
<GridView
android:id="@+id/year_4_badge_gridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
Upvotes: 1
Views: 2079
Reputation: 1908
You need to set your GridView height depending on the items. For more information check this link (it's with ListView, but for you it's the same, just notice that GridView have two items on one row and ListView have one) : http://blog.lovelyhq.com/setting-listview-height-depending-on-the-items/
Upvotes: 1
Reputation: 63
Override the onMeasure function.
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (bInScroll) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
else
super.onMeasure(widthMeasureSpec,heightMeasureSpec);
}
Upvotes: 0