ViewPager2 :VerticalStackTransformer
Published in
Apr 12, 2022
The idea is to Create a Vertical Stack Transformer for ViewPager2. In Search of an idea for this for my viewPager2. I came across this Article by Ahmed Radhouane Belkilani [https://tinyurl.com/36behbmx]. I modified this horizontal Transformer to vertical transformation.
- SetUp: Assuming that you have already created your viewPager2 code. Make sure that highlighted attributes are present in your XML. Orientation defines scroll direction.
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"/>
2 Let’s Move Towards Transformation
Don’t forget to set offscreenPageLimit value to set the page count that needs to be retained & also pass the same to the transformer.
viewPager.offscreenPageLimit = 3
viewPager.setPageTransformer(VerticalStackTransformer(3))
and it’s DONE.
I took inspiration from an article by Ahmed Radhouane Belkilani, you can refer to the below article. Thanks.
Reference: https://tinyurl.com/36behbmx