2014-06-07 82 views
0

出於某種原因,我不明白,還有我的網格行之間的間距,同時我已清楚設置垂直間距爲0。我想在我的兩個電網的XML,並在圖像的XML不同的寬度和高度設置打(網格組件)。GridView的高度間距

這是我有:

enter image description here

,這就是我想要的:

enter image description here

你可以看到網格XML和下面的圖片XML:

網格:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <GridView 
     android:id="@+id/gridView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:columnWidth="144dp" 
     android:horizontalSpacing="0dp" 
     android:verticalSpacing="0dp" 
     android:numColumns="auto_fit" 
     android:stretchMode="spacingWidthUniform" > 
    </GridView> 

</RelativeLayout> 

圖像:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RelativeLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" /> 

</RelativeLayout> 
+0

哇。這樣一個簡單的答案,我一直在尋找小時-_-; 非常感謝:D – Billakosama

回答

0

我猜follwoing的optins之一將解決問題的UT:

set imageview.setAdjustViewBounds(true); in adapter

或者

<GridView 
     android:stretchMode="none"> 
</GridView> 
+0

謝謝:)。第一次工作。 (我猜妳誰評論和刪除評論的人?) – Billakosama

+0

歡迎YESSS :) – KOTIOS

0

試試這個

<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/MyGrid" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="0dp" 
    android:verticalSpacing="2dp" 
    android:horizontalSpacing="2dp" 
    android:clipChildren="true" 
    android:alwaysDrawnWithCache="true" 
    android:numColumns="auto_fit" 
    android:columnWidth="100dp" 
    android:stretchMode="columnWidth" 
    android:gravity="center_horizontal"/>