GridView行间距填充屏幕

时间:2014-06-13 06:11:03

标签: java android android-layout android-gridview

我的网格视图在两行之间有空格。我试图删除空白区但没有成功。那么有谁能告诉我如何删除白色间距?

这是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >

    <GridView
        android:id="@+id/bg_chooser_grid"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:numColumns="auto_fit"/>

</LinearLayout>

这里是gridItem xml:

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/grid_item_img"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/app_name"
    android:scaleType="centerInside"
    android:src="@drawable/ic_launcher" />

适配器的重要部分&#34;:

 gridImg = (ImageView) vi.findViewById(R.id.grid_item_img);
 gridImg.setImageResource(data.get(position));

以下是它的外观: enter image description here

1 个答案:

答案 0 :(得分:0)

    Try This Code :- 

     <GridView
            android:id="@+id/gridView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="4dp"
            android:columnWidth="90dp"
            android:gravity="center"
            android:numColumns="auto_fit"
            android:stretchMode="columnWidth" >
        </GridView>


and customGridAdapter xml view:-


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="20dp"
    android:background="@drawable/grid_border"
    android:orientation="vertical"
    android:padding="5dp" >

    <ImageView
        android:id="@+id/item_image"
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:scaleType="fitXY"
        android:src="@drawable/home" >
    </ImageView>

</LinearLayout>

此图片用于LinearLayout android:background =&#34; @ drawable / grid_border&#34;

enter image description here