title: how to make selected tab in center
body: <p>I am facing a problem and i need a solution of it as soon as possible.
  I am working on android application.I have 8 tabs I want , when i click one of them then selected tab must come in centre.
   here is my code</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="bhitch.bhitch.com.bhitch.CategoryActivity"&gt;
  
  
      &lt;include
          android:id="@+id/toolbar_layout"
          layout="@layout/toolbar_layout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" /&gt;
  
      &lt;android.support.v4.view.ViewPager
          android:fitsSystemWindows="true"
          android:id="@+id/image_viewPager"
          android:layout_width="match_parent"
          android:layout_height="200dp"
          android:layout_below="@id/toolbar_layout"&gt;
  
          &lt;android.support.v4.view.PagerTabStrip
              android:id="@+id/firsttabstrip"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_gravity="top"/&gt;
  
      &lt;/android.support.v4.view.ViewPager&gt;
  
      &lt;android.support.design.widget.TabLayout
          android:id="@+id/tabLayout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignEnd="@id/image_viewPager"
          android:layout_gravity="bottom"
  
          android:layout_marginTop="150dp"
          app:tabGravity="center"
         app:tabMode="scrollable"
          app:tabSelectedTextColor="@color/tab_focus"
          app:tabTextColor="@android:color/white"&gt;
  
      &lt;/android.support.design.widget.TabLayout&gt;
  
      &lt;android.support.v4.view.ViewPager
          android:id="@+id/viewPager"
          android:layout_marginTop="5dp"
          android:layout_width="match_parent"
          android:layout_height="700dp"
          android:layout_below="@id/tabLayout"&gt;
  
          &lt;android.support.v4.view.PagerTabStrip
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:id="@+id/secondtabstrip"
              android:layout_gravity="top"/&gt;
  
      &lt;/android.support.v4.view.ViewPager&gt;
  
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>this is my Activity class</p>
  
  <pre><code>public class CategoryActivity extends AppCompatActivity {
      ViewPager viewPager;
      CategoryAdapter adapter;
      GridView gridView;
      Toolbar toolbar;
      TabLayout tabLayout;
      ViewPager imageViewPager;
      CategoryAdapter imageAdapter;
      ViewPagerAdapter viewPagerAdapter;
      PagerTabStrip firsttabstrip;
      PagerTabStrip secondtabstrip;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_category);
          toolbar = (Toolbar) findViewById(R.id.toolbar_layout);
          setSupportActionBar(toolbar);
  
         viewPager = (ViewPager) findViewById(R.id.viewPager);
          imageViewPager = (ViewPager) findViewById(R.id.image_viewPager);
          firsttabstrip=(PagerTabStrip)findViewById(R.id.firsttabstrip);
          secondtabstrip=(PagerTabStrip)findViewById(R.id.secondtabstrip);
       imageAdapter = new CategoryAdapter(this);
          imageViewPager.setAdapter(imageAdapter);
  
  
          tabLayout = (TabLayout) findViewById(R.id.tabLayout);
          toolbar.setTitle("Category Activity");
  
  
          viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
          viewPagerAdapter.addFragments(new HealthFragment(), "Health");
          viewPagerAdapter.addFragments(new BeautyFragment(), "Beauty");
          viewPagerAdapter.addFragments(new AutomobileFragment(), "Automobile");
          viewPagerAdapter.addFragments(new CinemaFragment(), "Cinema");
          viewPagerAdapter.addFragments(new FoodFragment(), "Food");
          viewPagerAdapter.addFragments(new BeautyFragment(), "Music");
          viewPagerAdapter.addFragments(new ElectronicFragment(), "Electronics");
          viewPagerAdapter.addFragments(new EducationFragment(), "Education");
  
  
  
          viewPager.setAdapter(viewPagerAdapter);
  
  
  
          tabLayout.setupWithViewPager(viewPager);
  
          // tabLayout.setupWithViewPager(imageViewPager);
  
  
  
  
                viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  
              @Override
              public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  
  
              }
  
  
                    @Override
              public void onPageSelected(int position) {
                  imageViewPager.setCurrentItem(position);
                  tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
  
              }
  
              @Override
              public void onPageScrollStateChanged(int state) {
  
  
              }
          });
  
  
          imageViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  
              @Override
              public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  
  
              }
  
              @Override
              public void onPageSelected(int position) {
                  viewPager.setCurrentItem(position);
                  tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
  
              }
  
              @Override
              public void onPageScrollStateChanged(int state) {
  
              }
          });
  
      }
  }
  </code></pre>
  
  <p>this is viewpageradapter class</p>
  
  <pre><code>public class ViewPagerAdapter extends FragmentPagerAdapter {
  
      ArrayList&lt;Fragment&gt; fragments = new ArrayList&lt;&gt;();
      ArrayList&lt;String&gt; tabTitles =  new ArrayList&lt;&gt;();
  
      public void addFragments(Fragment fragments , String titles ){
  
          this.fragments.add(fragments);
          this.tabTitles.add(titles);
      }
  
      public ViewPagerAdapter(FragmentManager fm){
          super(fm);
      }
      @Override
      public Fragment getItem(int position) {
          return fragments.get(position);
      }
  
      @Override
      public int getCount() {
          return fragments.size();
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          return tabTitles.get(position);
      }
  }
  </code></pre>
  
  <p>1st , 2nd , 7th, 8th tab is not coming in centre when i click on it and rest tabs are coming in centre . I wanna make a circular chain of tab so that when i click any of them then selected tab must come in centre. Thanks in advance.</p>