I am using this ExpandableHeightGridView class where the GridView
"supposedly" stretches to the content's height since I am placing it inside a ScrollView
. This works fine if my GridView
items are complete but since my GridView
items are dynamic, it has not the same number of items always, now the problem is if I have fewer GridView
items, its height doesn't wrap to the content height but has a space of blank row. I don't understand why it allocates that blank row.
Here's the layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SecondActivity" >
<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="@string/hello_world" />
<com.example.ExpandableHeightGridView
android:id="@+id/gridview_module"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:horizontalSpacing="20dp"
android:isScrollContainer="false"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
<Button
android:id="@+id/dial_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:onClick="dialPhone"
android:text="Dial Phone" />
</LinearLayout>
</ScrollView>
I am allocating the GridView weight of 1 and the others are 0. Am I getting it right?