このExpandableHeightGridViewクラスを使用しています。このクラスでは、GridView
「おそらく」がコンテンツの高さまで伸びScrollView
ます。GridView
アイテムが完全な場合、これは正常に機能しますが、GridView
アイテムは動的であるため、常に同じ数のアイテムがあるわけではありません。問題は、GridView
アイテムが少ない場合、その高さがコンテンツの高さに折り返されず、スペースがあることです空白行。その空白行を割り当てる理由がわかりません。
レイアウトは次のとおりです。
<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>
私は 1 の GridView の重みを割り当てていますが、他の重みは 0 です。