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?
3 Answers
The best solution would be to rotate the viewpager to 180:
mViewPager.setRotationY(180); //rotate the viewpager
then, rotate the inner view that contains the content of the tab for tablayout (to reverse the effect on the content).An example in the case of a textview:
if (textView.getRotationY() != 180) {
textView.setRotationY(180);
}
For PagerTabStrip, you should also rotate 180 the 3 visible tabs:
PagerTabStrip pt= container.findViewById(R.id.pager_tab_strip);
pt.getChildAt(0).setRotationY(180);
pt.getChildAt(1).setRotationY(180);
pt.getChildAt(2).setRotationY(180);
That worked for me in an arabic app. It should work also for any rtl locales.

- 958
- 2
- 18
- 35

- 91
- 1
- 3
-
3rotationY = 180 makes a swipe bug in android Pie (level 28) – Hamid Zandi Oct 23 '18 at 01:13
-
1@do01 why so? What did you do for Android P? – Rushi M Thakker Jan 10 '19 at 12:35
-
@RushiMThakker yes it don't let swipe normally :( – Hamid Zandi Jan 11 '19 at 21:17
-
In Android P there is jerk while swiping the viewpager. Anyone got solution for this ? – Shivani Rastogi Jul 31 '19 at 12:55
-
So did you find any solution for Pie? – Eren Tüfekçi Dec 02 '19 at 11:15
-
I have added answer – Alok Gupta Jan 02 '20 at 06:03
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

- 1,806
- 22
- 21
I have faced this case before and there are 2 solutions
1- let us assume that you have 4 fragments F1,F2,F3 and F4, now you have to fetch all fragments in adapter in reversely as this F4,F3,F2 and F1, once you load your fragments set the select fragment is = pager.setCurrentItem(Titles.length - 1);
and make sure to reverse the titles also.
the second solution is to use custom view pager like
hope you handle this

- 919
- 14
- 30
-
Problem with first solution is i want to tabs start from right side in rtl locales but with this solution they starts from end and first tab is fourth from left and problem with second solution is that i cant use fragmentPagerAdapter with this custom viewpagers – Mkhakpaki Oct 19 '17 at 12:45