3

この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 です。

4

2 に答える 2

2

これをアクティビティに追加してみてください。

ExpandableHeightGridView exGridView;

exGridView = (ExpandableHeightGridView) findViewById(R.id.myId);
exGridView .setExpanded(true);

私はあなたのリンクからそれを基にしました。

于 2013-09-23T02:41:09.093 に答える
0

layout_weight を指定する場合は、layout_height が 0dp であることを確認してください。layout_height と layout_weight の両方を設定しないでください。お役に立てば幸いです。

また、このタグ android:fillViewport="true" をスクロール ビューから削除します。実際には、fillViewport を true に設定することで、アイテムが少ない場合にグリッドビューを拡大するようにスクロールビューに要求しています。このタグを削除すると、グリッドビューはそのコンテンツに折り返され、行の下に余分なスペースがなくなります。

于 2013-11-01T10:03:16.677 に答える