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:
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.
StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams)holder.itemView.getLayoutParams();
p.setFullSpan()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With