Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewPager for screen slides from right to left

I am using ViewPager for screen slide it works fine for language's script from left to right but for Arabic script which is actually right to left is not feasible

can i swipe pages of viewpager in reverse order?

like image 310
Hammad Ali Butt Avatar asked Feb 14 '23 07:02

Hammad Ali Butt


2 Answers

Try this,

viewPager.setCurrentItem(ViewPagerSize);

and this will make user swipe right to left

like image 91
Prakash M Avatar answered Feb 24 '23 05:02

Prakash M


At the time of this post, ViewPager still doesn't handle RTL correctly. Here's a a workaround when using TabLayout:

  1. Set android:layoutDirection="ltr" in the TabLaout XML, so it will always display left-to-right.
  2. Before you call setupWithViewPager(viewPager), check if running in RTL, and if so, reverse the order of the tabs, and start with the last tab:

    if (MyApp.isRTL()) {
        Collections.reverse(pgAdapter.fragmentList);
        viewPager.setCurrentItem(pgAdapter.getCount() - 1);
    }
    

RTL can be checked using the following code:

public static boolean isRTL() {
    final int directionality = Character.getDirectionality(
            Locale.getDefault().getDisplayName().charAt(0));
    return directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT ||
            directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC;
}
like image 42
jazzgil Avatar answered Feb 24 '23 03:02

jazzgil