I have a RecyclerView as a Calendar, and each view is a day.
(occupying the full width and height of the screen)
.----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------.
| .--------------. | | .--------------. | | .--------------. | | .--------------. | | .--------------. | | .--------------. | | .--------------. |
| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | (1) | | | | (2) | | | | (3) | | | | (4) | | | | (5) | | | | (...) | | | | (n) | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| '--------------' | | '--------------' | | '--------------' | | '--------------' | | '--------------' | | '--------------' | | '--------------' |
'----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------'
The problem:
The problem is, when a user is trying to scroll to a date that is very far away in the future, i.e move ahead 40 days, onBindViewHolder
runs for all the 39 children in-between, which wastes resources, as the scroll is so fast, no-one even knows what each day contains during that scroll.
As a result the last day takes some time before it shows the content, because the main thread is busy drawing all the in-between days that will never be visible unless the user scrolls manually to them anyway.
What's needed:
How can I prevent the RecyclerView from going crazy loading all those in-between days, when all I need at that point is just the day the user ends up to.
.----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------.
| .--------------. | | .--------------. | | .--------------. | | .--------------. | | .--------------. | | .--------------. | | .--------------. |
| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | (1) | | | | (2) | | | | (3) | | | | (4) | | | | (5) | | | | (...) | | | | (n) | |
| | LOAD | | | | DONT | | | | DONT | | | | DONT | | | | DONT | | | | DONT | | | | LOAD | |
| '--------------' | | '--------------' | | '--------------' | | '--------------' | | '--------------' | | '--------------' | | '--------------' |
'----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------'
(Please don't tell me to use scrollToPosition
instead of smoothScrollToPosition
since removing the animation is not an option)
Thank you