title: Android align bottom doesn't work correctly
body: <p>I am doing an android app where I need to align the layout of the fragment in a tab with the bottom of the app bar of the navigation view. The problem is that the imageView appears above the app bar (instead of the android:layout_alignBottom="@id/appbar") and in adittion the ScrollView does not work.</p>
  
  <p>I have the navigation view where I have the following code:</p>
  
  <pre><code>@Override
  public boolean onNavigationItemSelected(MenuItem item) {
      int id = item.getItemId();
  
      Fragment currFragment = null;
      FragmentManager fragmentManager = getSupportFragmentManager();
  
      if (id == R.id.nav_principal) {
          currFragment = new FastAccessFragment();
      } else if (id == R.id.nav_logout) {
          editor.putBoolean("signedUp", false);
          editor.apply();
          Intent intent = new Intent(this, LoginActivity.class);
          if (intent != null) {
              this.finish();
              startActivity(intent);
          }
      }
  
      if (currFragment != null) {
          fragmentManager
                  .beginTransaction()
                  .replace(R.id.content_main, currFragment)
                  .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
                  .commit();
      }
  
      setTitle(item.getTitle());
  </code></pre>
  
  <p>Where the content_main layout has the following 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:id="@+id/content_main_d"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      tools:showIn="@layout/app_bar_main"&gt;
  
      &lt;android.support.v7.widget.Toolbar
          android:id="@+id/toolbar_fragment"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="?attr/colorPrimary"
          android:minHeight="?attr/actionBarSize"
          android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
          app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Then, in the Fragment FastAccessFragment I create three tabs with their corresponding tabs as you can see here:</p>
  
  <pre><code>public class FastAccessFragment extends Fragment {
  
      private ViewPager viewPager;
      private AppBarLayout appBar;
      View rootview;
      TabLayout tabLayout;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          rootview = inflater.inflate(R.layout.fast_access_fragment, container, false);
  
          if (savedInstanceState == null) {
  
              View parent = (View) container.getParent();
              appBar = (AppBarLayout) parent.findViewById(R.id.appbar);
              tabLayout = new TabLayout(getActivity());
              tabLayout.setTabTextColors(Color.parseColor("#C0C0C0"), Color.parseColor("#FFFFFF"));
              tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#FFA500"));
              appBar.addView(tabLayout);
  
              viewPager = (ViewPager) rootview.findViewById(R.id.pager_fragment);
  
              Adapter adapter = new Adapter(getFragmentManager());
  
              adapter.addFragment(new VoiceFragment(), "Voice");
              adapter.addFragment(new ButtonsFragment(), "Buttons");
              adapter.addFragment(new PicturesFragment(), "Pictures");
  
              viewPager.setAdapter(adapter);
  
              tabLayout.setupWithViewPager(viewPager);
  
              tabLayout.getTabAt(0).setIcon(R.drawable.microphone);
              tabLayout.getTabAt(1).setIcon(R.drawable.hand_up);
              tabLayout.getTabAt(2).setIcon(R.drawable.frame);
          }
  
          return rootview;
      }
  
      @Override
      public void onDestroyView() {
          super.onDestroyView();
          appBar.removeView(tabLayout);
      }
  
      public class Adapter extends FragmentStatePagerAdapter {
          private final List&lt;Fragment&gt; fragments = new ArrayList&lt;&gt;();
          private final List&lt;String&gt; fragmentTitles = new ArrayList&lt;&gt;();
  
          public Adapter(FragmentManager fm) {
              super(fm);
          }
  
          @Override
          public android.support.v4.app.Fragment getItem(int position) {
              return fragments.get(position);
          }
  
          @Override
          public int getCount() {
              return fragments.size();
          }
  
          public void addFragment(android.support.v4.app.Fragment fragment, String title) {
              fragments.add(fragment);
              fragmentTitles.add(title);
          }
  
          @Override
          public CharSequence getPageTitle(int position) {
              return fragmentTitles.get(position);
          }
      }
  
  }
  </code></pre>
  
  <p>The ButtonsFragment has the following code:</p>
  
  <pre><code>    public class ButtonsFragment extends Fragment {
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_buttons, container, false);
  
          Button up = (Button) view.findViewById(R.id.up_button);
          Button up_2 = (Button) view.findViewById(R.id.up_button_2);
          Button up_3 = (Button) view.findViewById(R.id.up_button_3);
          Button up_4 = (Button) view.findViewById(R.id.up_button_4);
          Button up_5 = (Button) view.findViewById(R.id.up_button_5);
  
          final ImageView im = (ImageView) view.findViewById(R.id.blind_image);
  
          up.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  im.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.blind0, null));
              }
          });
  
          up_2.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  im.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.blind1, null));
              }
          });
  
          up_3.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  im.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.blind2, null));
              }
          });
  
          up_4.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  im.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.blind3, null));
              }
          });
  
          up_5.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  im.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.blind4, null));
              }
          });
  
          return view;
      }
  }
  </code></pre>
  
  <p>And finally I have the layout fragment_buttons where the ScrollView and the alignBottom don't work:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_alignBottom="@id/appbar"
      tools:context="com.blindsiot.carlos.blindsiot.VoiceFragment"&gt;
  
      &lt;ScrollView
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical"&gt;
  
              &lt;ImageView
                  android:layout_width="200dp"
                  android:layout_height="200dp"
                  android:id="@+id/blind_image"
                  android:layout_gravity="center"
                  android:src="@drawable/blind0" /&gt;
  
              &lt;Button
                  android:id="@+id/up_button"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center"
                  style="@style/Widget.AppCompat.Button.Colored"
                  android:text="PRUEBA"/&gt;
  
              &lt;Button
                  android:id="@+id/up_button_2"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center"
                  style="@style/Widget.AppCompat.Button.Colored"
                  android:text="PRUEBA"/&gt;
  
              &lt;Button
                  android:id="@+id/up_button_3"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center"
                  style="@style/Widget.AppCompat.Button.Colored"
                  android:text="PRUEBA"/&gt;
  
              &lt;Button
                  android:id="@+id/up_button_4"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center"
                  style="@style/Widget.AppCompat.Button.Colored"
                  android:text="PRUEBA"/&gt;
  
              &lt;Button
                  android:id="@+id/up_button_5"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center"
                  style="@style/Widget.AppCompat.Button.Colored"
                  android:text="PRUEBA"/&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/ScrollView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>You can see the result here: <a href="https://i.stack.imgur.com/jbEbT.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jbEbT.jpg" alt="enter image description here"></a></p>
  
  <p>And the expected result would be the image view above the app bar in the same layout of the buttons and all of them in a scroll view.</p>
  
  <p>The layout that corresponds with the Pager and that inflates the FastAccessFragment has this code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v4.view.ViewPager
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/pager_fragment"
      android:layout_width="match_parent"
      android:layout_height="match_parent" /&gt;
  </code></pre>
  
  <p>The code of the app_bar_main layout that contains the app bar is the following:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.design.widget.CoordinatorLayout 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"
      android:fitsSystemWindows="true"
      tools:context="com.blindsiot.carlos.blindsiot.MainActivity"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:id="@+id/appbar"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/AppTheme.AppBarOverlay"&gt;
  
          &lt;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/AppTheme.PopupOverlay" /&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;RelativeLayout
          android:id="@+id/content_main"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>