Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tabs Swipe direction in Right to Left Android app

I have an Android app that has tabs. I want the app to be Right to Left.
I put android:supportsRtl="true" in the manifest file, and changed some of the elements to be android:layoutDirection="rtl".

It changes everything to right to left, which is what I want, except that it reversed the swiping direction in the tabs- when you swipe to the left, it moves to the left tab, instead of the opposite from the swipe. I want to change it to make it a regular swipe.

This is my code:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:fitsSystemWindows="true"
android:id="@+id/drawer_layout">
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layoutDirection="rtl">
    <include
        android:id="@+id/toolbar"
        android:gravity="right"
        layout="@layout/toolbar" />
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/main_layout"
        android:layout_below="@id/toolbar">
        <com.refractored.PagerSlidingTabStrip
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:textColor="#ecf0f1"
            app:pstsShouldExpand="true"/>

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            tools:context=".MainActivity" />
    </LinearLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:id="@+id/nav_view"
    android:layoutDirection="rtl"
    app:headerLayout="@layout/header"
    app:menu="@menu/nav_menu" />
</android.support.v4.widget.DrawerLayout>

Hope you can help me.

Thanks!

like image 480
amitairos Avatar asked May 12 '16 20:05

amitairos


People also ask

How do you swipe view on Android?

You can create swipe views using AndroidX's ViewPager widget. To use ViewPager and tabs, you need to add a dependency on ViewPager and on Material Components to your project. To insert child views that represent each page, you need to hook this layout to a PagerAdapter .

How do I use TabLayoutMediator on Android?

Establish the link by creating an instance of this class, make sure the ViewPager2 has an adapter and then call attach() on it. Instantiating a TabLayoutMediator will only create the mediator object, attach() will link the TabLayout and the ViewPager2 together.


1 Answers

I added:

android:layoutDirection="ltr" to TabLayout.

NOT

android:layoutDirection="rtl"

and it worked just fine

like image 150
EAGLE4YE Avatar answered Nov 28 '22 14:11

EAGLE4YE