我正在使用这个 ExpandableHeightGridView GridView
“应该”延伸到内容高度的类,因为我将它放在 ScrollView
中。如果我的 GridView
项目是完整的,这就可以正常工作,但由于我的 GridView
项目是动态的,它总是没有相同数量的项目,现在问题是如果我有更少的 GridView
项,它的高度没有换行到内容高度,但有一个 blank 行的空间。我不明白为什么它分配那个空白行。
布局如下:
<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。我做对了吗?
最佳答案
尝试在您的 Activity 中添加这个。
ExpandableHeightGridView exGridView;
exGridView = (ExpandableHeightGridView) findViewById(R.id.myId);
exGridView .setExpanded(true);
我根据你的 link .
关于android - 可扩展的 GridView 高度不会扩展到内容的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18910033/