Search code examples
androidandroid-viewpagerandroid-tablayout

Android rtl viewpager with rtl tablayout


I know this question may seem duplicated but i couldn't find a good solution for my problem. I am using tablayout with viewpager with fragmentPagerAdapter as adapter of viewpager. As you know viewpager is not supporting rtl layout so i have problems in rtl locales. I want to tabs start from right(first tab stick to right side of screen) and user can swipe correctly. How can i do this? Any help?


Solution

  • Good news guys :). Android recently added new UI component called ViewPager2.

    https://developer.android.com/jetpack/androidx/releases/viewpager2

    Please find below the code and links :

    dependencies {
        implementation "androidx.viewpager2:viewpager2:1.0.0"
    }
    

    Improvements from the previous ViewPager implementation:

    • RTL (right-to-left) layout support
    • Vertical orientation support
    • Reliable Fragment support (including handling changes to the underlying Fragment collection)
    • Dataset change animations (including DiffUtil support)

    Below link explains about Migration guide from ViewPager to ViewPager2:

    https://developer.android.com/training/animation/vp2-migration

    Also we have demo example :

    https://github.com/android/views-widgets-samples/tree/master/ViewPager2