title: TabLayout remove unnecessary scrolling
body: <p>I've encountered the tricky problem with android TabLayout</p>
  
  <pre><code>import android.support.design.widget.TabLayout;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/UPKsS.gif"><img src="https://i.stack.imgur.com/UPKsS.gif" alt="To see what&#39;s going on, look at this gif"></a></p>
  
  <p>When I select the foremost tab to the left, then scroll tabs to the right and select the foremost tab to the right, TabLayout first shows me the left tab again and then scrolls to selected tab to the right. Here's my setup code</p>
  
  <pre><code>    void setupTabs(ViewPager viewPager, TabLayout tabLayout) {
         ProductsPagerAdapter adapter = new ProductsPagerAdapter(getChildFragmentManager(), rootCategory.getChildCategories());
         viewPager.setAdapter(adapter);
         tabLayout.setupWithViewPager(viewPager);
  
         setStartingSelection(viewPager, adapter);
  
  
     }
  
      private void setStartingSelection(ViewPager viewPager, ProductsPagerAdapter adapter) {
          for(int i = 0 ; i &lt; adapter.getCount(); i++){
              String title = (String) adapter.getPageTitle(i);
              if(title.equals(selectedCategory.getName())){
                  viewPager.setCurrentItem(i);
                  break;
              }
          }
      }
  </code></pre>
  
  <p>And layout</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:fitsSystemWindows="true"
          android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"&gt;
  
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="@color/toolbar_color"
              app:navigationIcon="@drawable/ic_back_white"
              app:title="@string/title_transport"
              app:titleTextColor="@color/title_color"/&gt;
  
  
          &lt;android.support.design.widget.TabLayout
              android:id="@+id/tab_layout"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              app:tabMode="scrollable"
              app:tabTextColor="@color/white"
              app:tabIndicatorColor="@color/tab_indicator"
              app:tabGravity="fill"/&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;android.support.v4.view.ViewPager
          android:id="@+id/viewpager"
          android:layout_width="match_parent"
          android:layout_height="0px"
          android:layout_weight="1"
          android:background="@android:color/white" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>