2012-04-17 3 views
1

GridView에 표시되는 내 조각 사이에 경계선을 가져 오려고합니다. GridView의 배경색을 흰색으로 설정하고 조각의 색상을 검정색으로 설정했습니다. 그때 나는 그 코드 라인을 삽입 :Android GridView 세로 테두리

int border = 2; // px 
view.setColumnWidth((dm.widthPixels/2)-(4*border)); 
view.setNumColumns(2); 
view.setHorizontalSpacing(border); 
view.setVerticalSpacing(border); 

viewGridView입니다.

결과는 GridView 전체의 왼쪽과 위쪽과 아래쪽의 조각 사이에 좋은 테두리가 있습니다. 그러나 두 조각 사이에는 테두리가 없습니다.

<?xml version="1.0" encoding="utf-8"?> 
<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/overview" 
    android:stretchMode="columnWidth" 
    android:clipChildren="true" > 

</GridView> 

누군가가 도움이 될 수있다

다음은 GridView 내 선언입니다.

+0

그리드 항목 레이아웃의 배경으로 일부 패딩 또는 (9patch) 드로어 블을 설정할 수 없습니까? –

+0

나는 너의 힌트를 완전히 이해하지 못한다. 무슨 뜻인지 설명해 주시겠습니까? – Henrik

+0

@Henrik : 몇 줄에 맞지 않을 것이므로 대답으로 설명을 추가했습니다. :) 그런 다음 댓글에 다음 번에 회신 할 때'@ '(예 :'@ MH.')을 추가하십시오. 그러면 응답자에게 해당 사실을 알립니다. –

답변

5

음을 접견, 내 이전의 코멘트에 대해 설명하려고했던 일 : GridView 원하는 간격, 왜 그리드 항목이 알아서 만들려고하지 않는 규제 갖는 대신에? 이것에 대한 쉬운 해결책 중 하나는 GridView의 어댑터에 사용/배치 된 레이아웃 파일의 배경으로 적절한 드로어 블을 설정하는 것입니다. 즉, 그리드 항목에 사용하는 레이아웃입니다. 당신이 언급 한 조각들.

빠른 예 : 마지막에서 마법을

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/grid_background" 
    android:gravity="center" 
    android:text="Text" 
    android:textColor="@android:color/white" /> 

을 그리고 : 그것의 내부 항목에 사용되는

<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gridview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/white" 
    android:numColumns="4" /> 

과 레이아웃 :

GridView를 타고 배경 드로어 블 :

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android">  
    <stroke android:width="5dp" android:color="@android:color/white" />  
    <padding android:bottom="5dp" android:left="5dp" android:right="5dp" 
     android:top="5dp" />  
    <solid android:color="@android:color/black" />  
</shape> 

결과는 다음 될 것입니다 :

gridview with 'borders'

나는 수평 및 수직 간격 매개 변수 그런데, 당신을 위해 작동하지 않는 이유를 모르겠어요.

GridView : 나는 사람들을 사용할 때, 나는 위의 그림에서와 매우 유사한 효과를 얻을 수 있어요

<?xml version="1.0" encoding="utf-8"?> 
<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gridview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/white" 
    android:horizontalSpacing="10dp" 
    android:numColumns="4" 
    android:verticalSpacing="10dp" /> 

항목 레이아웃 (단순히 고정 된 색의 이전 배경 자원을 교환) :

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/black" 
    android:gravity="center" 
    android:text="Text" 
    android:textColor="@android:color/white" /> 

결과 :

another gridview with 'borders'

,

희망이 있으면 도움이 될 것입니다.

+0

두 솔루션을 모두 시도했지만 그 중 아무 것도 작동하지 않았습니다. 조각의 외부 LinearLayout에 "android : background ="@ drawable/grid_layout ""문을 삽입했습니다. 그게 맞습니까? – Henrik

+0

죄송합니다. grid_layout을 사용하는 솔루션이 정상적으로 작동합니다! 내가 배경 코드를 설정 한 부분 코드에서 라인을 찾았습니다. 이 선을 제거하면 모든 것이 완벽합니다. 감사!! – Henrik

+0

어댑터를 사용하여 TextViews를 설정하면 어떻게됩니까? TextView의 XML도 넣어야합니까? –