Sliding tab layout for right to left languages
Asked Answered
M

3

7

I'm using SlidingTabLayout and i want to slide tabs from right to left, but i can't find a way.

I already try 'setGravity()' method but it doesn't work.

Mischa answered 28/1, 2015 at 12:46 Comment(2)
which language you are using for RTLRomaic
@MuhammadBabar I changed gravity of container layout in SlidingTabLayout.java and setCurrentItem of viewPager to the last item and it worksMischa
R
3

Maybe you need try layout mirroring:

To take advantage of RTL layout mirroring, simply make the following changes to your app:

  1. Declare in your app manifest that your app supports RTL mirroring. Specifically, add android:supportsRtl="true" to the element in your manifest file.

  2. Change all of your app's "left/right" layout properties to new "start/end" equivalents. If you are targeting your app to Android 4.2 (the app's targetSdkVersion or minSdkVersion is 17 or higher), then you should use “start” and “end” instead of “left” and “right”. For example, android:paddingLeft should become android:paddingStart. If you want your app to work with versions earlier than Android 4.2 (the app's targetSdkVersion or minSdkVersion is 16 or less), then you should add “start” and end” in addition to “left” and “right”. For example, you’d use both android:paddingLeft and android:paddingStart.

Romaic answered 28/1, 2015 at 13:44 Comment(0)
I
0

you can use

 android.support.design.widget.TabLayout

from library android.support.design from newest SDK and apply Xcihnegan answer above

Indeterminism answered 12/1, 2016 at 5:37 Comment(0)
N
0

I have tried and fix this by this:

 private void scrollToTab(int tabIndex, int positionOffset) {
        if (isRtlMode()) {
            scrollToTabRtl(tabIndex, positionOffset);
        } else {
            scrollToLtr(tabIndex, positionOffset);
        }
    }

 private void scrollToTabRtl(int tabIndex, int positionOffset) {
        final int maxItemCount = mTabStrip.getChildCount();
        if (maxItemCount == 0 || tabIndex < 0 || tabIndex >= maxItemCount) {
            return;
        }
        View activeItemView = mTabStrip.getChildAt(tabIndex);
        if (activeItemView != null) {
            int totalWidth = getWidth();
            int targetScroll = totalWidth - activeItemView.getRight() + positionOffset;
            super.smoothScrollTo(-targetScroll, 0);
        }
    }
Nabob answered 9/12, 2019 at 6:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.