Search code examples
javaandroidkotlinandroid-viewpagerandroid-viewpager2

is it possible to change the default direction of a ViewPager Android?


It is possible to override the action of switching screens of a ViewPager that by default drags to the sides (from left to right and vice versa) to pass the screen with movements from top to bottom and from bottom to top?


Solution

  • You can change the default direction to top-to-bottom by using the orientation attribute of ViewPager2.

    <androidx.viewpager2.widget.ViewPager2
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/pager"
       android:orientation="vertical" />