Is it posible to change layoutmanager for a different viewtype?

Published

Actually I have two viewtypes, a recyclerview is showing the elements in a gridLayout fashion.

Problem is that one of those elements in the grid should be show horizontally with a linearlayout aspect and the others as a grid.

How can I manage this ?

override fun getItemViewType(position: Int): Int {
        return if(position %5 == 0) 1 else 0
    }

This is my recyclerview

binding.rv_mylist.adapter = TestAdapter()
binding.rv_mylist.layoutManager = GridLayoutManager(requireContext(), 3)

in conclusion, what I need is that viewtype 1 shows with a LinearLayoutManager and viewtype 0 with a GridLayoutManager

Source: Android Questions

Published
Categorized as android, android-adapter, android-recyclerview, kotlin

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq