Android ViewPager2: Multiple Transform (Kotlin)

use CompositePageTransformer
val animTransformer = ViewPager2.PageTransformer { page, position ->    page.apply {        val r = 1 - abs(position)        page.alpha = 0.25f + r        page.scaleY = 0.85f + r * 0.15f    }}val pageMarginPx = 10.dpToPx(resources.displayMetrics)val marginTransformer = MarginPageTransformer(pageMarginPx)val transformer = CompositePageTransformer().apply {    addTransformer(animTransformer)    addTransformer(marginTransformer)}viewPager.setPageTransformer(transformer)

NOTE: Convert Dp to Pixel - dpToPx

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.