2014-10-22 64 views
0

我想刪除Gridview中的列或行的網格之間的任何空格。任何幫助將不勝感激。刪除gridview中的網格之間的空格

這裏是我的xml文件中的GridView

<GridView 
    android:id="@+id/grid" 
    android:layout_width="fill_parent" 
    android:layout_height="400dp" 
    android:layout_marginTop="50dp" 
    android:listSelector="@android:color/transparent" 
    android:fadingEdgeLength="0px" 
    android:alwaysDrawnWithCache="true" 
    android:clipChildren="true" 
    android:columnWidth="100dp" 
    android:gravity="center_horizontal" 
    android:numColumns="auto_fit" 
    android:scrollingCache="true" 
    android:smoothScrollbar="true" 
    android:stretchMode="columnWidth" 
    android:verticalSpacing="2dp"></GridView> 

這裏是我的everycell.xml file.Hope這將有助於

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" 
android:layout_width="fill_parent" 
android:layout_height="50dp" 
> 


<ImageView 
    android:layout_height="120dp" 
    android:layout_width="120dp" 
    android:layout_weight="1" 
    android:id="@+id/imageView" 
    android:gravity="center" 
    android:adjustViewBounds="true" 
    android:orientation="vertical"/> 

    <TextView 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:id="@+id/text" 
     android:textSize="18sp" 
     android:textStyle="bold" 
     android:singleLine="true" 
     android:textColor="@android:color/black" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

</RelativeLayout> 
+0

刪除垂直間距 – 2014-10-22 10:53:10

+0

不行,不起作用。 – Soham 2014-10-22 10:55:28

+0

試過columnWidth =「wrap_content」? – 2014-10-22 10:56:17

回答

0

在您的行項目xml中放置您的RelativeLayout的背景顏色。您應該看到網格項目之間沒有空格。

+0

是的,這是我的錯誤。我已經完成了代碼。我正在下載的圖像在每一面都有填充,我認爲它是在那裏放置的。 – Soham 2014-10-22 12:12:58

+0

沒問題,很高興我能幫忙:) – 2014-10-22 12:39:03

0

layout_width="fill_parent"將基於列的寬度產生額外的空間。

eq:如果gridview = 440dp,columnWidth = 100dp,則會有40dp的額外空間。它將分佈在你的列之間。

所以, 要麼你可能需要使用`layout_width =「WRAP_CONTENT」

,或者您可能需要基於在GridView

的寬度或設置項寬度爲wrap_content並計算動態設置columnWidth時numColumns動態