This is the working solution I was able to come up with.
onCreate
class:
val displayMetrics = baseContext.resources.displayMetrics
//setting the "zoomed in" effect on the image
image.layoutParams.width = displayMetrics.widthPixels + displayMetrics.widthPixels / 2
val originalWidth = image.layoutParams.width
scroll_view.setOnScrollChangeListener { _: NestedScrollView?, _: Int, y: Int, _: Int, _: Int ->
//adjust "if" check and formula as you wish
if (y < 200) {
image.layoutParams.width = (originalWidth - y*1.5).toInt()
image.requestLayout()
}
}
Some clarifications. I change the image's width based on the size of the screen, so that the image is "zoomed in" at first, and then it zooms out to it's original form, as the user scrolls down.
Also make sure you have recyclerView.setNestedScrollingEnabled(false);
on the RecyclerView you wish to scroll smoothly.
The result if the following:
