As shown in the picture above, I want to darken the previous & next items in the ViewPager2.
setPageTransformer(object : ViewPager2.PageTransformer {
override fun transformPage(page: View, position: Float) {
page.translationX = -pageTranslationX * position
page.scaleY = 1 - (0.15f * abs(position))
}
})
I'm showing the preview with the above snippet, but I couldn't find a way to darken it.
Is there a good solution?

You can utilize the
positionparameter, that maps to the current position of the page, to get a color shade based on the page position; this also will benefit in grading the colors between the most darken & most lighten colors so that the color changes gradually:ColorUtils.blendARGB()to get a color based on percentage of the position.pageResult: