0

Please show me how to resolve this problem, I want all tabs will spread to entire screen width in case have a few tabs, but auto matic scroll in case have many tabs. How to detect have a tabs is out of display screen in scroll mode ?

Thanks

2 Answers2

0

TabLayout has a field named tabMode if you want it to be scrollable then set is to TabLayout.MODE_SCROLLABLE

Here is the full doc

/**
 * Scrollable tabs display a subset of tabs at any given moment, and can contain longer tab
 * labels and a larger number of tabs. They are best used for browsing contexts in touch
 * interfaces when users don’t need to directly compare the tab labels.
 *
 * @see #setTabMode(int)
 * @see #getTabMode()
 */
public static final int MODE_SCROLLABLE = 0;

I would also suggest you not to make the mode scrollable unless you have a minimum of 6 tabs

Gil Goldzweig
  • 1,809
  • 1
  • 13
  • 26
0

If you want the tabs to be occupied the fullwidth of the screen, you need to assign app:tabGravity=”fill” to TabLayout. If there are three tabs it will adjust in the screen bounds if more than three then it automatically give a scroll functionality

Rest please refer the link for complete tour of tablayout

https://www.androidhive.info/2015/09/android-material-design-working-with-tabs/