Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable horizontal scroll in tab like Google Play?

I'm referencing a great demo here regarding material design. It has tabs, but when I add too many the tab items get squished (see screenshot). How can I make it scroll horizontally?

enter image description here

I believe below is the layout I should make the change, but I combed the docs and can't seem to get it, pls help!

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:id="@+id/main_content"     android:layout_width="match_parent"     android:layout_height="match_parent">      <android.support.design.widget.AppBarLayout         android:id="@+id/appbar"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">          <android.support.v7.widget.Toolbar             android:id="@+id/toolbar"             android:layout_width="match_parent"             android:layout_height="?attr/actionBarSize"             android:background="?attr/colorPrimary"             app:popupTheme="@style/ThemeOverlay.AppCompat.Light"             app:layout_scrollFlags="scroll|enterAlways" />          <android.support.design.widget.TabLayout             android:id="@+id/tabs"             android:layout_width="match_parent"             android:layout_height="wrap_content" />      </android.support.design.widget.AppBarLayout>      <android.support.v4.view.ViewPager         android:id="@+id/viewpager"         android:layout_width="match_parent"         android:layout_height="match_parent"         app:layout_behavior="@string/appbar_scrolling_view_behavior" />      <android.support.design.widget.FloatingActionButton         android:id="@+id/fab"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="end|bottom"         android:layout_margin="@dimen/fab_margin"         android:src="@drawable/ic_done" />  </android.support.design.widget.CoordinatorLayout> 
like image 871
TruMan1 Avatar asked Jul 02 '15 20:07

TruMan1


People also ask

How do I turn on horizontal scrolling?

Horizontal scrolling can be achieved by clicking and dragging a horizontal scroll bar, swiping sideways on a desktop trackpad or trackpad mouse, pressing left and right arrow keys, or swiping sideways with one's finger on a touchscreen.

How do I insert a scroll horizontal?

Click File > Options. On the Advanced tab, scroll to the Display section. Select Show horizontal scroll bar and Show vertical scroll bar, and then click OK.

Is horizontal scrolling accessible?

Users may ignore content accessible through horizontal scrolling or “swiping” as they don't expect content there. Our research found that even strong cues such as arrows frequently remain unnoticed. People expect to scroll vertically for additional content, but they don't expect to scroll sideways.


1 Answers

TabLayout has a method setTabMode() which can be either MODE_FIXED (default) or MODE_SCROLLABLE which is what you need.

You can also define this in XML with app:tabMode="scrollable".

like image 87
Lamorak Avatar answered Sep 21 '22 22:09

Lamorak