I have a basic carousel logic, set in ViewPager2.PageTransformer I can observe previous and next views, also have applied scaling.
But I need to improve this logic, when it's the first item in the carousel I need it to be shifted left by offset, when it's a last on shift it right by the offset. How to do so?
I can't really figure out how to implement this function, theoretically it's possible to get current's item index, but animation won't be smooth, at least what I tried.
What I currently do:
Find offset by which central view should be moved(offset of the scaled view)
val cardWidthPlusPaddings = view.width + padding * 2F
val desiredCardWidthPlusPaddings = cardWidthPlusPaddings + padding
val cardScale: Float = cardWidthPlusPaddings/desiredCardWidthPlusPaddings
val currentCardWidth = cardWidthPlusPaddings * cardScale
val offset = ((cardWidthPlusPaddings - currentCardWidth)/2) - padding
Setting the traslationX:
It will only move left and right items by scaled offset + paddings, not the central one.
And also I'd like to omit calculation of the right and left cards scaling, can add them later.
view.translationX = position * -(2 * padding + offset)

I was manage to solve it