10行代码让 ViewPager2实现这样效果
val centerPageScale = 0.7f
bind.viewPager2.offscreenPageLimit = 3
bind.viewPager2.setPageTransformer { page, position ->
page.isGone = abs(position) >= bind.viewPager2.offscreenPageLimit
page.elevation = 10 - abs(position)
val pagerWidth: Int = bind.viewPager2.width
val horizontalOffsetBase = (pagerWidth - pagerWidth * centerPageScale) / 2 / bind.viewPager2.offscreenPageLimit
page.translationX = (horizontalOffsetBase - page.width + 50f) * position
val scaleFactor = (centerPageScale - abs(position) * 0.1f)
page.scaleX = scaleFactor
page.scaleY = scaleFactor
}