I have RecyclerView with images. It based on this solution. Images are lazy loaded into view with Glide. I need to add zoom on central image like in this:
How can i do it?
I have RecyclerView with images. It based on this solution. Images are lazy loaded into view with Glide. I need to add zoom on central image like in this:
How can i do it?
The most direct way to affect what you want is to extend
LinearLayoutManager
. As you've no doubt discovered, hooking into the scroll events properly is a pain:So let's extend the manager. We'll create a few parameters that you might expose.
Fill out your constructors, and then override
scrollHorizontallyBy
:Call the parent's version and save the distance travelled. We'll need to return this at the end of the method:
We are going to set up a simple linear interpolation. It looks nice enough.
Loop through all of the active children of the control, run the interpolation, and set the scale of the child.
This is almost all you need. One final step is to make sure that this adjustment is called after initialization -- otherwise the zooming won't take effect until the first time the control is moved:
And that's all there is to it. Super responsive, and you can drop this new layout manager into any horizontal recycler.