title: TabLayout or horizontal scrollview Android
body: <p>Image for the TabLayout that I wanted to achieve.
  <a href="https://i.stack.imgur.com/CSCnj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CSCnj.png" alt="enter image description here"></a></p>
  
  <p>Can somebody shows me the way to achieve this?</p>
  
  <p>My code:</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.TabLayout
          android:id="@+id/sliding_tabs"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          app:tabMode="scrollable"
          app:tabGravity="center"/&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>
  
  <p>I already set the attributes <code>app:tabMode="scrollable"</code> and <code>app:tabGravity="center"</code> but all the tabs just stick to the left in the layout.</p>
  
  <p>I wanna achieve the result like the above image no matter how many the tabs are. Means the position of the tabs will away at the center or the tablayout.</p>
  
  <p>PageFragment.java:</p>
  
  <pre><code>package com.example.testing;
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  
  // In this case, the fragment displays simple text based on the page
  public class PageFragment extends Fragment {
      public static final String ARG_PAGE = "ARG_PAGE";
  
      private int mPage;
  
      public static PageFragment newInstance(int page) {
          Bundle args = new Bundle();
          args.putInt(ARG_PAGE, page);
          PageFragment fragment = new PageFragment();
          fragment.setArguments(args);
          return fragment;
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          mPage = getArguments().getInt(ARG_PAGE);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_page, container, false);
          TextView textView = (TextView) view;
          textView.setText("Fragment #" + mPage);
          return view;
      }
  
  
  }
  </code></pre>
  
  <p>SampleFragmentPagerAdapter.java:</p>
  
  <pre><code>package com.example.testing;
  
  import android.content.Context;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  
  
  
  public class SampleFragmentPagerAdapter extends FragmentPagerAdapter {
      final int PAGE_COUNT = 3;
      private String tabTitles[] = new String[] { "Tab1", "Tab2", "Tab3" };
      private Context context;
  
      public SampleFragmentPagerAdapter(FragmentManager fm, Context context) {
          super(fm);
          this.context = context;
      }
  
      @Override
      public int getCount() {
          return PAGE_COUNT;
      }
  
      @Override
      public Fragment getItem(int position) {
          return PageFragment.newInstance(position + 1);
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          // Generate title based on item position
          return tabTitles[position];
      }
  }
  </code></pre>
  
  <p>TabActivity.java:</p>
  
  <pre><code>package com.example.testing;
  
  import android.support.design.widget.TabLayout;
  import android.support.v4.view.ViewPager;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  
  public class TabAcitivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_tab_layout);
  
          // Get the ViewPager and set it's PagerAdapter so that it can display items
          ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
          viewPager.setAdapter(new SampleFragmentPagerAdapter(getSupportFragmentManager(),TabAcitivity.this));
  
          // Give the TabLayout the ViewPager
          TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
          tabLayout.setupWithViewPager(viewPager);
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/TVM3g.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TVM3g.jpg" alt="enter image description here"></a></p>
  
  <p>The tabs start from the left. How do I place it to make it start at the middle? Or is it better to use a horizontal scrollable ListView?</p>