title: Android how to position TabLayout to the bottom of the screen (for Google's material design library TabLayout)
body: <p>I am trying to use a TabLayout joined with a ViewPager to create three swipeable fragments. However, I ran against a problem: <strong>I want the TabLayout to be at the bottom of the screen, but the ViewPager is forcing it to be at the top</strong>.</p>
  
  <p>TabLayout used to be in the <em>android.support.design.widget</em> library. This library, however, has been changed since androidx was introduced. The new library is <em>com.google.android.material.tabs.TabLayout</em>.</p>
  
  <p>Previous (and outdated) posts (<a href="https://stackoverflow.com/questions/41481536/android-tablayout-on-the-bottom-of-the-screen">example1</a>, <a href="https://stackoverflow.com/questions/34871848/tablayout-position-at-the-bottom-of-the-screen">example2</a>) suggest a simple solution to the above problem by simply creating a vertical <code>LinearLayout</code> and specifying the <code>ViewPager</code> and <code>TabLayout</code> as two separate elements of that <code>LinearLayout</code>.</p>
  
  <p>The above solution is no longer viable due to the fact that now, you have to specify the <code>TabLayout</code> to be an element inside of the <code>ViewPager</code> (<a href="https://developer.android.com/guide/navigation/navigation-swipe-view" rel="nofollow noreferrer">reference</a>), like this:</p>
  
  <pre><code>&lt;androidx.viewpager.widget.ViewPager
      android:id="@+id/pager"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
  
      &lt;com.google.android.material.tabs.TabLayout
          android:id="@+id/tab_layout"
          android:layout_width="match_parent"
          android:layout_height="48dp"
          &gt;
      &lt;/com.google.android.material.tabs.TabLayout&gt;
  &lt;/androidx.viewpager.widget.ViewPager&gt;
  </code></pre>
  
  <p>Then, to "merge" the <code>ViewPager</code> with the <code>TabLayout</code>, the <code>setupWithViewPager(ViewPager vp)</code> method has to be called on the <code>TabLayout</code> instance:</p>
  
  <pre><code>ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
  MainPagerAdapter mpa = new MainPagerAdapter(getSupportFragmentManager(), 3);
  viewPager.setAdapter(mpa);
  
  TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
  tabLayout.setupWithViewPager(viewPager);
  </code></pre>
  
  <p><strong>Now, how can I neatly make the TabLayout go to the bottom of the ViewPager, either from xml code or programmatically?</strong></p>