Bookends icon indicating copy to clipboard operation
Bookends copied to clipboard

Add support for GridLayoutManager

Open pushbit opened this issue 9 years ago • 4 comments

The API looks great, though I would like to use it with GridLayoutManager as well.

pushbit avatar May 19 '15 11:05 pushbit

It works with GridLayoutManager. The only additional step is to implement GridLayoutManager's setSpanSizeLookUp in your view or adapter if necessary for your header & footers so that it spans the # of columns in the grid. I'll provide an example shortly.

https://developer.android.com/reference/android/support/v7/widget/GridLayoutManager.html

KevinTCoughlin avatar May 20 '15 12:05 KevinTCoughlin

What do you think about adding another Bookends constructor that also takes a GridLayoutManager and sets a SpanSizeLookup that causes the headers and footers to span all columns? I imagine that's the most common use case and it would be nice if the client didn't have to think about the headers and footers beyond adding them.

pushbit avatar May 21 '15 11:05 pushbit

I have some concerns before coupling the adapter & layout manager:

  • You'd still have to roll your own if you wanted a header or footer to not span all columns
  • Orientation change w/ linear <-> grid managers would be a bit clumsy unless you did a single column grid in portrait instead of linear
  • It makes the component a tiny bit less flexible

Constructors that allow for a lookup definition or number of columns may be ok. It's definitely not ideal that this does not work properly w/ grid layouts without a few extra lines of code.

@mlapadula thoughts?

KevinTCoughlin avatar May 21 '15 12:05 KevinTCoughlin

Supporting grid layouts seems sensible -- I know you have a solution that already works, and it'd be cool to make it available because it takes a few hours (at least) to figure out if you're unaware of it.

It does kind of suck that we're coupling the adapter and layout manager, but we're already kind of doing that since this implementation only works with LinearLayoutManager :p

mlapadula avatar May 21 '15 14:05 mlapadula