RecyclerView GridLayout width full width and half width
Asked Answered
O

3

6

Is there any way to archieve the following? I want my RecyclerView to be able to display my Cards in a grid of 2 columns, but I also want a couple of cards to have the full screen width, not just the half width. I tried using StaggeredGridLayoutManager to archive that, but I cannot find a method to archive that.

EDIT I want the layout to look like this: enter image description here

Onehorse answered 31/12, 2015 at 12:28 Comment(9)
"I also want a couple of cards to have the full screen width" is NOT "i want my recyclerview to be able to display my cards in a grid of 2 columns". Full-screen sized items are mutually exclusive with your 2 columns idea. Work out what you want and/or draw a picture to illustrate please.Elfont
@Elfont sorry if I wasn't clear enough. I added an image to better illustrate itOnehorse
Use a combination of layouts? Like grid, with linearlayouts for each non-fullwidth region.Undesigning
You can try GridLayout>LinearLayout orientation horizontal>GridLayout /LinearLayout weight 0.5. Not the most efficient implementation probably but it should be possible. I'd give you some sample code if my laptop didn't die on me a few days back...Undesigning
@Undesigning could you give me any code example on how to implement this with recyclerview and layoutmanager?Onehorse
oops sorry seems I missed the main point. never really used that before yet. I'll go tinker around a bit tomorrow and see what comes up.Undesigning
@Undesigning thank you very much for your helpOnehorse
Don't thank me yet I haven't done anything lol. Will reply around this time tomorrow regardless of whether I can get anything outUndesigning
aye didn't manage to do much. i will see what i can do.Undesigning
D
5

To expand on shuo Han's answer, say you want a recyclerview with some items spanning full width and others only spanning half width. What you would do is:

yourRecyclerView.layoutManager = StaggeredGridLayoutManager(2, RecyclerView.VERTICAL)

and then inside your adapter, if you want an itemview to span the full width, you write this code in onBindViewHolder:

val layoutParams = holder.itemView.layoutParams as StaggeredGridLayoutManager.LayoutParams
layoutParams.isFullSpan = true

Otherwise do not use anything, it will span half way.

Dibble answered 7/4, 2019 at 14:0 Comment(0)
W
1
StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams)holder.itemView.getLayoutParams();

p.setFullSpan()

Waterrepellent answered 28/4, 2016 at 12:6 Comment(0)
B
0

Have a look at RecyclerView with a StaggeredGridLayoutManager

Boiler answered 16/2, 2016 at 13:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.