Im developing an RTL app which uses TabLayout (Scrollable mode) and ViewPager for sliding fragment pages ! after testing it for different api i've notice abnormal behavier of TabLayout in api 17 and 18!
then i think maybe there was something wrong with my xml or my code! i decide to use a third party library to avoid this issue but same result happend!
after investigating with that third party library owner we notice that both the library and TabLayout use HorizontalScrollView and maybe thats the problem!
investigation link : https://github.com/ogaclejapan/SmartTabLayout/issues/107
please guide me to resolve this!
is there a way to use HorizontalScrollView which is inside api 23 for api 17 and 18 ?
Steps to reproduce the problem :
Hard way : create a new project and inside that use following xml and code and run it on api 17 or 18 emulator.
buildToolsVersion "23.0.2"
compileSdkVersion 23
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layoutDirection="rtl"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ir.heandshe.testinghorizontal.MainActivity">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:tabMode="scrollable"/>
</RelativeLayout>
MainActivity.java :
public class MainActivity extends AppCompatActivity {
private TabLayout tabs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabs = (TabLayout) findViewById(R.id.tabs);
for (int i=0 ; i<=10;i++) {
tabs.addTab(tabs.newTab().setText("test " + i));
}
}
}
Easy way : use following link and clone the library and run demo on emulator 17 or 18! (RTL section in demo app) --> https://github.com/ogaclejapan/SmartTabLayout
What happened :
1 - Tabs move in wrong direction
2 - They wont fill the ViewPort! in some cases they start from the middle of the screen! :((
normal behavier is to work like when its work in api 19+
please be sure that you test it in RTL mode ! LTR has no problem!
How can I create a library from android SDK source?
According to this issue, it's a bug in ViewPager library
There is a trick to solve this but it's not the best way
In your TabLayout xml add this line:
android:layoutDirection="ltr"
This will prevent TabLayout from mirroring in RTL devices and it will match ViewPager direction.
P.S. I have same problem on api 25 and support library 25.1.0. This trick solved it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With