2013-03-22 19 views
3
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:background="#FFFFFF" 
    android:layout_gravity="center" 
    android:padding="5dip" > 
    <GridView 
     android:id="@+id/homeGridView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:columnWidth="200dip" 
     android:adjustViewBounds="true" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:horizontalSpacing="0dip" 
     android:numColumns="2" 
     android:stretchMode="spacingWidthUniform" 
     android:verticalSpacing="10dip" /> 
</LinearLayout> 
  1. 我在網格視圖四個圖標,但它們之間的間距是 太多。我想減少它。
  2. 另外我想使GridView中心到設備,但總是 停留在頂部。

回答

6

您應該使用維度來解決此問題。 只需爲每個密度屏幕定義尺寸。

  • 值-LDPI
  • 值-MDPI
  • 值-HDPI
  • 值-xhdpi
  • 值-大

值-LDPI/dimesion.xml

<resources> 
    <dimen name="grid_vertical_space">15dp</dimen> 
</resources> 

值-MDPI/dimesion.xml

<resources> 
    <dimen name="grid_vertical_space">20dp</dimen> 
</resources> 

值-HDPI/dimesion.xml

<resources> 
    <dimen name="grid_vertical_space">30dp</dimen> 
</resources> 

喜歡明智..

請試試這個

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:background="#FFFFFF" 
    android:layout_gravity="center" 
    android:padding="5dip" > 
    <GridView 
     android:id="@+id/homeGridView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:columnWidth="200dip" 
     android:adjustViewBounds="true" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:horizontalSpacing="0dip" 
     android:numColumns="2" 
     android:stretchMode="columnWidth" 
     android:verticalSpacing="@dimen/grid_vertical_space" /> 
</LinearLayout> 
+0

感謝阿米特,水平空間仍然是圖像和整個電網中顯示的同樣是不下來... – theJava 2013-03-22 10:37:28

0

如果您的佈局僅由4個圖標組成,爲什麼不使用TableLayout和2 TableRow?我認爲你可以更容易地實現你想要的,因爲:

  1. 你可以定義項目之間的間距;
  2. 你也可以居中你的表。
+0

http://stackoverflow.com/questions/15570372/making-the-gridview-center在Android可以幫助我在這個線程...我差不多已經完成但尚未能做到這一點...我不想使用TableLayout和TableRow。 – theJava 2013-03-22 12:31:49

+0

@theJava完成了,但是如果你有這個線程的答案,發佈它;)。 – JJ86 2013-03-22 12:50:24