0

I'm wondering how we can style the whole row containing more than 1 item in a GridLayout (so the columnCount is set to 2 or above).

Trying to style all the items in the same row to fake styling the whole row is not what I want. Although doing like that works in some cases but not for all cases.

Here is a screenshot helping you understand more about what I want:

enter image description here

There are 2 rows as in the image above, the effect here is just a simple continuous shadowed and white background (without any space between the 2 items or at least visually looked like that), but that's just for demonstrative purpose. The actual effect may be various and more complicated and that's when styling each item may not solve the problem easily.

I've tried Googling around but there is nothing helpful found. In fact the number of items is not fixed, there is a list of items, and I would like to show them in a RecyclerView with layout manager set to GridLayoutManager. Technically we can just style each item using some template XML. Based on that, I can only think of the idea to group each 2 items in a larger item (called a row). Treat each row as one item, so we can style the row as the whole. However doing so may complicate the underlying data (because now the items are not flat, they are grouped by 2 adjacent items), also to have those grouped items we need to perform one more step (grouping) on the input items. If the number of items is small enough, doing something like that is acceptable, however if they are very large (as usually the case in reality) I don't think we should follow that approach.

halfer
  • 19,824
  • 17
  • 99
  • 186
Hopeless
  • 4,397
  • 5
  • 37
  • 64
  • have you tried android:verticalSpacing="-dp" –  Aug 12 '16 at 11:49
  • I guess that is applied only on the `GridLayout` directly, here I'm using a `RecyclerView` with a `GridLayoutManager` although we can have the same effect by using some custom `ItemDecoration` to adjust the spacing. However doing like so is just some kind of fake, not styling the whole row as I said in my question. In fact I would like to use a `CardView` style for the whole row (not for each item). The style applied on each item separately to fake the whole row is also not easy. Thanks. – Hopeless Aug 12 '16 at 23:50
  • Check grid layout manager class it should have that property –  Aug 13 '16 at 06:48
  • check this post http://stackoverflow.com/questions/28531996/android-recyclerview-gridlayoutmanager-column-spacing –  Aug 13 '16 at 12:51
  • @YasirAli that's about `ItemDecoration` (which I've known of) - it is just a way to add style on ***each item*** not ***each row*** in this case. I'm sure there is not any easy way to achieve what I want here in the way I want. (I've programmed with WPF before, it can help build rich complicated UI in desktop app easily but even with it I still cannot think of any easy solution to have the same style in desktop app). – Hopeless Aug 13 '16 at 13:24

0 Answers0