I have used the Android Design Support library and implemented tabs in my android app using tablayout, fragments and viewpager. Tab sliding is working perfectly. But when I add more tabs (say 7), those tabs reduce their width and adjust themselves. How to show only 3 tabs at a time and show the next three when the user slides from 3rd to 4th tab?
TabLayout is used to implement horizontal tabs. TabLayout is released by Android after the deprecation of ActionBar. TabListener (API level 21). TabLayout is introduced in design support library to implement tabs. Tabs are created using newTab() method of TabLayout class.
It provides a horizontal layout to display tabs on the screen. We can display more screens on a single screen using tabs. We can quickly swipe between the tabs.
In your MainActivity
ViewPager mpager;
TabPageAdapter adapter = new TabPageAdapter(getSupportFragmentManager(), list);
mtabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
mpager.setOffscreenPageLimit(list.size());
mpager.setAdapter(adapter);
In your xml TabLayout set
app:tabMode="scrollable"
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