I got a recyclerview. I want to implement a carousel effect with fixed Y-Axis like this:
I wrote a custom LinearLayoutManager to be able to modify the recyclerview scrolling behaviour.
I try to get an horizontal scroll with Y-Axis fixed to the bottom of the view and X-Axis to the center of the view.
private val mShrinkAmount = 0.30f
private val mShrinkDistance = 1f
override fun onLayoutChildren(recycler: RecyclerView.Recycler?, state: RecyclerView.State?) {
super.onLayoutChildren(recycler, state)
scrollHorizontallyBy(0, recycler, state)
}
override fun scrollHorizontallyBy(dx: Int, recycler: RecyclerView.Recycler?, state: RecyclerView.State?): Int {
val scrolled = super.scrollHorizontallyBy(dx, recycler, state)
val scalePoint = (width / 2f)
val d0 = 0f
val d1 = (mShrinkDistance * scalePoint)
val s0 = 1f
val s1 = (1f - mShrinkAmount)
for (index in 0..(childCount - 1)) {
val child = getChildAt(index)
val childMidPoint = ((getDecoratedLeft(child!!) + getDecoratedRight(child)) / 2f)
val d = Math.min(d1, Math.abs(scalePoint - childMidPoint))
val scale = (s0 + (s1 - s0) * (d - d0) / (d1 - d0))
child.scaleX = scale
child.scaleY = scale
child.pivotY = (getDecoratedBottom(child) * 1f)
}
return scrolled
}
I set the value of pivotY to the bottom of the view here
child.pivotY = (getDecoratedBottom(child) * 1f)
But the result is not clean as you can see here:
The bottom of the views are not aligned and I got different padding on the right and left side when scrolling.
What did I miss?