1

我有这个网格视图,在 LinearLayout 内

LinearLayout 高度为 match_parent 或 fill_parent GridView 高度为 fill_parent 或 match_parent

但它仍然留下那个空白空间......我想拉伸 Gridview 内容以填充 LinearLayout

请帮忙!

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <GridView
            android:id="@+id/gridview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="6dp"
            android:gravity="center"
            android:horizontalSpacing="2dp"
            android:numColumns="3"
            android:stretchMode="columnWidth"
            android:verticalSpacing="2dp" />
    </LinearLayout>
4

3 回答 3

1

哦,我可以看到你在做什么。它根本不可能。即使你使用强烈反对的黑客来做这件事,你也将违反使用GridViewand的所有规则ListView。我强烈建议你不要在GridView这里使用。而是使用简单的嵌套LinearLayouts 或TableLayout. GridView并且ListView应该滚动。无论如何android:layout_weight="float",在使用LinearLayout.

于 2013-10-05T14:18:46.713 回答
0
// try this
 <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

        <GridView
                android:id="@+id/gridview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="6dp"
                android:gravity="center"
                android:horizontalSpacing="2dp"
                android:numColumns="3"
                android:stretchMode="columnWidth"
                android:verticalSpacing="2dp" />
    </LinearLayout>
于 2013-10-05T11:19:10.397 回答
0

您需要将线性布局和滚动视图的高度设置为wrap_content。这样做的目的是使您设置的视图组只与它包含的 ui 组件一样大。对您的 LinearLayout 执行此操作:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

android这个给你滚动视图:

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
于 2013-10-05T11:21:31.703 回答