我正在使用这个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>
我把GridView的权重设置为1,其他的都是0。我的理解正确吗?
exGridView.setExpanded(true);
使其拉伸,但它会拉伸到整个高度而不是实际的GridView
高度。例如,我的最大GridView
行数为4,但如果只有2行,它会分配2行空白行。 - Compaq LE2202x