CardStackView icon indicating copy to clipboard operation
CardStackView copied to clipboard

How can I use different layout (xml) for every card?

Open RasyiidWho opened this issue 5 years ago • 1 comments

RasyiidWho avatar Mar 12 '20 05:03 RasyiidWho

This will be expensive to destroy and inflate fully new layouts for every item, but can be done.

The card stack is a recyclerview, and you can extend ListAdapter<X, Y> for your CardStackAdapter implementation to handle this. You will need to determine the layout type based on position, and then build the appropriate ViewHolder:

override fun getItemViewType(position: Int): Int {
     return  someCustomLogicToDeterminLayoutResourceByPosition(position)
}

Then in onCreateViewHolder you'll need to build the appropriate ViewHolder for the layout type. This will likely require a base class for your ViewHolders, and custom ViewHolders per type of item.

I would recommend finding a way to NOT have unique layouts per card if you have a large number of cards in your stack, as it will be expensive. But it is possible.

Barryrowe avatar Mar 20 '20 14:03 Barryrowe