I want to change the height of all views within a recycler view at once. All items can have different heights (defined by their visible views, so not hard-coding possible).
With the press of a button, the heights of all items are changed to a smaller height. To do that, I'm looping through the recycler views and get every single one using findViewHolderForAdapterPosition(int position). This works fine for the visible items on the screen but not for the ones at the edge of the screen. It seems they are already drawn but not yet visible. As a result, findViewHolderForAdapterPosition will return nil for them. And I can't find a way to access them properly. I could use notifyItemChanged(int position) but this results in a weird animation.
Here's the simplified code I'm using to loop through the views and do the animations:
private var dataList = listOf<Any>() // Content list
fun animate(recycler: RecyclerView, isLarge: Boolean) {
this.isLarge = isLarge
for (it in dataList.indices) {
val v = recycler.findViewHolderForAdapterPosition(it)
if (v is ContentViewHolder) { // check type
if (isLarge) { // Transition isLarge -> small
v.binding.animateSmallToLarge(it) // changes visibility using GONE & VISIBLE
} else { // Transition short -> long
v.binding.animateLargeToSmall(it) // changes visibility using GONE & VISIBLE
}
}
}
}
Now I'm a super rookie on Android/Kotlin, so any hint will help! It seems that the animation that cases the views to reduce its size will make these "not accessible but drawn outside the screen" suddenly visible. How can I properly access them or invalidate them so they get redrawn (NOT using notifyItemChanged)? Any ideas?