viewPager.apply { clipToPadding = false // allow full width shown with padding clipChildren = false // allow left/right item is not clipped offscreenPageLimit = 2 // make sure left/right item is rendered}// increase this offset to show more of left/rightval offsetPx = 30.dpToPx(resources.displayMetrics)viewPager.setPadding(offsetPx, 0, offsetPx, 0)// increase this offset to increase distance between 2 itemsval pageMarginPx = 10.dpToPx(resources.displayMetrics)val marginTransformer = MarginPageTransformer(pageMarginPx)viewPager.setPageTransformer(marginTransformer)
NOTE: Convert Dp to Pixel - dpToPx
NOTE: I am using androidx.viewpager2:viewpager2:1.0.0-beta02