Android GridView draw dividers

Eric Chen picture Eric Chen · Aug 20, 2011 · Viewed 52k times · Source

I'd like to know the simplest way to draw dividers between items (currently textviews) within a GridView. The only way I can think of is to draw borders around those textviews so when combined, they look like continuous horizontal and vertical dividers.

There is a setDivider() for listviews but not gridviews?

Thanks.

Answer

Fenix Voltres picture Fenix Voltres · Jul 9, 2012

In case you want just simple lines as borders, much, much simpler is setting a background color for a GridView and proper padding & spacing:

<GridView
    (...)
    android:background="@color/LightGold"
    android:listSelector="@android:color/transparent"
    android:horizontalSpacing="1dip"
    android:verticalSpacing="1dip"
    android:paddingLeft="1dip"
    android:paddingTop="1dip" />