2011-10-24 4 views

답변

109

당신의 GridView 태그 android:verticalSpacingandroid:horizontalSpacing를 사용하고 요구 사항에 따라 간격을 제공 할 수 있습니다. 예를 들어

: horizontalSpacing 안드로이드 :

<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

에 추가하여 여기에 명시된 대답은 그리드 항목 사이의 간격을 제공하지만 첫 번째 행 그리드 항목과 작업 표시 줄 사이의 간격은 어떻게됩니까? –

+0

@Ramswaroop 당신은 마진을 사용할 수 없습니까? –

+0

격자 항목에서'marginTop'을 시도했지만 작동하지 않습니다. GridView에'paddingTop'을 적용했는데 간격이 생겼지 만 여전히 간격이 남아있을 때 더 많은 명확성을위한 스크린 샷을 참조하십시오 : http : // imgur. com/LBrB6N5 –

2

사용이

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

작동합니까? 어댑터 –

1

내가

안드로이드를 사용하려고했다

을 verticalSpacing을하고 나에게 더 성공을주지 않았다.

기본적으로 나는 모든 요소에 여백을 추가했습니다. 어쩌면이 방법으로 모든 요소와 마찬가지로 구성 할 수 있기 때문에 더 나은 지점 일 수 있습니다. 이것은이

<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"/> 
그래서 내가 GridLayout과 여섯 개 이미지를 가지고 내 방식으로 모습입니다

. 2 행 3 행.

관련 문제