I'm trying to implement the carousel-like effect in recyclerView like this. I can't find the right function for scaling and moving the views. Also, the views that reached the top of recyclerview must not scroll out of recyclerview's edges but stick to them
override fun scrollVerticallyBy(dy: Int, recycler: RecyclerView.Recycler?, state: RecyclerView.State?): Int {
for (i in 0 until childCount) {
val item = getChildAt(i)
val recyclerCenter = height / 2f
val distance = max(abs(recyclerCenter - getDecoratedTop(item!!) / 2f), recyclerCenter - getDecoratedTop(item) / 2f)
val ratio = (recyclerCenter - item.height / 2f - distance) / (recyclerCenter - item.height / 2f) + 1
item.translationZ = (ratio * 1000f)
item.alpha = ratio
item.translationY = -(ratio.pow(2)*10)
item.scaleX = ratio
item.scaleY = ratio
}
return super.scrollVerticallyBy(dy, recycler, state)
}
I've already tried some solutions, like carousellayoutmanager, but all of them scaling all views, that not in center of recyclerview