2011-10-24 28 views

答えて

109

にあなたはGridViewのタグにandroid:verticalSpacingandroid:horizontalSpacingを使用することができますし、あなたの要件ごとに間隔を提供。例えば

: アンドロイドをhorizo​​ntalSpacing:

<GridView 
     android:layout_height="wrap_content" 
     android:id="@+id/gridView1" 
     android:layout_width="match_parent" 
     android:numColumns="auto_fit" 
     android:horizontalSpacing="10dp"  // space between two items (horizontal) 
     android:verticalSpacing="10dp">  // space between two rows (vertical) 
    </GridView> 
+0

を追加することで、ここで述べた答えはグリッド項目間の間隔を提供しますが、第1行のグリッド項目とアクションバーの間隔はどのようにして取得できますか? –

+0

@Ramswaroopはそれにマージンを使用できませんか? –

+0

グリッドアイテム上で 'marginTop'を試しましたが、動作しません。GridViewに' paddingTop'を適用しました。スペースがありますが、スクロールしてもまだスペーシングが残っています。詳細はhttp:// imgurを参照してください。 com/LBrB6N5 –

2

使用このBaseAdapter

imageView.setLayoutParams(new GridView.LayoutParams(150, 150)); 
imageView.setPadding(1, 1, 1, 1); 
+0

それは機能しますか?アダプタ –

1

私は

アンドロイドを使用しようとしていた

をverticalSpacingをし、それは私に何の成功を与えませんでした。

基本的に私はすべての要素に余白を追加しました。この方法ですべての要素のように構成することができるので、おそらくそれはより良い点です。

これは、だから私はGridLayoutの中に6つのイメージを持っている、それは私の方法で

<GridLayout 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_centerInParent="true" 
android:columnCount="2" 
android:rowCount="3"> 
<ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="128dp" 
    android:layout_height="128dp" 
    app:srcCompat="@drawable/ic_recipe" 
    android:layout_marginBottom="30dp" 
    android:layout_marginRight="15dp"/> 

<ImageView 
    android:id="@+id/imageView3" 
    android:layout_width="128dp" 
    android:layout_height="128dp" 
    app:srcCompat="@drawable/ic_add_recipe" 
    android:layout_marginBottom="30dp" 
    android:layout_marginLeft="15dp"/> 

<ImageView 
    android:id="@+id/imageView4" 
    android:layout_width="128dp" 
    android:layout_height="128dp" 
    app:srcCompat="@drawable/ic_favorite_recipies" 
    android:layout_marginBottom="30dp" 
    android:layout_marginRight="15dp"/> 

<ImageView 
    android:id="@+id/imageView6" 
    android:layout_width="128dp" 
    android:layout_height="128dp" 
    app:srcCompat="@drawable/ic_information" 
    android:layout_marginBottom="30dp" 
    android:layout_marginLeft="15dp"/> 

<ImageView 
    android:id="@+id/imageView5" 
    android:layout_width="128dp" 
    android:layout_height="128dp" 
    app:srcCompat="@drawable/ic_settings" 
    android:layout_marginRight="15dp"/> 

<ImageView 
    android:layout_width="128dp" 
    android:layout_height="128dp" 
    app:srcCompat="@drawable/ic_exit" 
    android:layout_marginLeft="15dp"/> 

のように見えるものです。 2行と3行

関連する問題