I'm a swift developer and I was able to build this layout very easily using a UICollectionView. However, I'm struggling to do the same in Kotlin. I've been trying to use a Recycler View to do this but it's not working out. Any advice on how I can do this would be highly appreciated.

- 312
- 1
- 3
- 13
-
can you post what have you done so far and it's result? – Yrii Borodkin Feb 22 '20 at 13:37
1 Answers
I can help you with a few suggestions as to how I would be making this layout. Check if it's of any help:
First, follow this post for implementing multiple viewtypes in your recyclerview by overriding getItemViewType()
method in your recyclerview adapter. You can set the item's viewtype based on its position in the datalist or a value in your datasource etc. Based on this viewtype returned you can set what your viewholder should look like in the adapter's onCreateViewHolder()
and the funtionality in onBindViewHolder()
method.
Next your recyclerview will need to make use of a GridLayoutManager
with vertical orientation and 2 columns.
With these 2 steps you can have multiple views in different columns as you require, BUT in order to have a viewholder occupy whole width like the 2nd row in your sample image you will need to make use of setSpanSizeLookup()
method of your grid layout manager. You can use this post here for reference.
Basically this is all you need to achieve your layout. Make use of multiple viewtypes for recyclerview with a gridlayout manager having a custom spansize lookup.
The references i mentioned are mostly in java but converting them to kotlin should be fairly easy. Have a look and let us know if this helps.

- 1,496
- 1
- 11
- 14
-
Thank you very much for this amazing reply. You really helped me out, especially with the second link. I'm using Groupie to make things easier and with setSpanSizeLookUp() I was able to do what I needed. – Minon Weerasinghe Feb 24 '20 at 09:31