ViewPager2 | Different fragment widths

48 Views Asked by At

I want to make ViewPager2 with two fragments with different width, but with the same start and end margins. The width of first fragment is match_parent with a 56dp end-margin. The width of second fragment is 256dp.

This is the result I get with the code below

Result I get

XML

<androidx.viewpager2.widget.ViewPager2 android:id="@+id/viewPager2" android:layout_width="match_parent" android:layout_height="wrap_content" />

Kotlin

binding.viewPager2.clipToPadding = false binding.viewPager2.clipChildren = false binding.viewPager2.setPadding(getDpValue(16), 0, getDpValue(56), 0) binding.viewPager2.setPageTransformer(MarginPageTransformer(getDpValue(16)))

And finally, this is the result I want (here I'm holding ViewPager2 without swiping it)

enter image description here

0

There are 0 best solutions below