Question

How to align the tabs in the ViewPager to the right instead of the left? I am using android.support.v4.view.ViewPager if that matters.

enter image description here

I've tried android:layout_gravity="right" but it doesn't affect the alignment:

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="right">
</android.support.v4.view.ViewPager>
Was it helpful?

Solution

Thanks to @CommonsWare for his help. I just needed to change this line:

tabsContainer = new LinearLayout(context);

to

tabsContainer = new LinearLayout(context);
tabsContainer.setGravity(Gravity.RIGHT);

OTHER TIPS

Or you just add this line:app:pstsShouldExpand="true"

to be:

<com.example.PagerSlidingTabStrip
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="48dip"
    app:pstsShouldExpand="true" />

You should be setting it to

 <android.support.v4.view.PagerTitleStrip
...
android:layout_gravity="right"
/>

Use this code :

tabsContainer.setLayoutDirection(LAYOUT_DIRECTION_RTL);
tabsContainer.setGravity(Gravity.RIGHT);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top