Is there a way to show (horizontal) dividers between rows in a gridview?
I tried putting a small divider-image below every grid item, but this is not a solution, bec
Just wanted to share how I implemented this using the link accepted by OP.
For my case I also needed to control the length of the separators, so I couldn't get around subclassing GridView
.
public class HorizontalSeparatorGridView extends GridView {
// Additional methods
@Override
protected void dispatchDraw(Canvas canvas) {
final int count = getChildCount();
for(int i = 0; i < count; i++) {
View child = getChildAt(i);
int bottom = child.getBottom();
int left = child.getLeft();
int right = child.getRight();
Paint paint = new Paint();
paint.setColor(0xffececec);
paint.setStrokeWidth(Math.round(0.5 * density));
int offset = // Some offset
canvas.drawLine(left + offset, bottom, right - offset, bottom, paint);
}
super.dispatchDraw(canvas);
}
I subclassed dispatchDraw
as opposed to onDraw
just to be safe but I don't think it would matter in this case.