title: Bottom Navigation Bar pushes down when changing between fragments
body: <p>In my activity i have a bottom navigation bar and the frame layout to show the fragments everything works fine but the problem is when i start moving from 1 - 4 in sequence the bottom navigation bar stays in its position but when i jump suddenly from 4 to 2 then the bottom navigation bar goes out of screen and when again clicked on the same item then it comes to normal position. </p>
  
  <p>This video will clearly help you get what my problem is <a href="https://drive.google.com/open?id=1YlkH2lLm1Ppf8DkgljQPjLTjNcjMKf6X" rel="nofollow noreferrer">Click to watch.</a></p>
  
  <p>as i guess this is a major problem when considering the UI so kindly help me how can i achieve this. For making things easier i'm posting my codes which contain these elements.</p>
  
  <p>activity_appMain.xml</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=".AppFragments.AppMain"&gt;
  
      &lt;FrameLayout
          android:id="@+id/fragments_container"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_above="@id/navigation_bar"/&gt;
  
      &lt;com.google.android.material.bottomnavigation.BottomNavigationView
          android:id="@+id/navigation_bar"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:background="?android:attr/windowBackground"
          app:labelVisibilityMode="labeled"
          app:menu="@menu/bottom_navigation" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>AppMain.java</p>
  
  <pre><code>package com.coderedinnovations.allioservices.AppFragments;
  
  import androidx.annotation.NonNull;
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.fragment.app.Fragment;
  
  import android.content.pm.ActivityInfo;
  import android.content.res.Configuration;
  import android.os.Bundle;
  import android.util.DisplayMetrics;
  import android.view.MenuItem;
  import android.view.WindowManager;
  
  import com.coderedinnovations.allioservices.AppFragments.FeedbackFragment;
  import com.coderedinnovations.allioservices.AppFragments.HomeFragment;
  import com.coderedinnovations.allioservices.AppFragments.MyOrdersFragment;
  import com.coderedinnovations.allioservices.AppFragments.MyProfileFragment;
  import com.coderedinnovations.allioservices.R;
  import com.google.android.material.bottomnavigation.BottomNavigationView;
  import com.google.firebase.iid.FirebaseInstanceId;
  
  public class AppMain extends AppCompatActivity {
  
      public void adjustFontScale(Configuration configuration){
  
          configuration.fontScale = (float) 0.9;
          DisplayMetrics metrics = getResources().getDisplayMetrics();
          WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
          wm.getDefaultDisplay().getMetrics(metrics);
          metrics.scaledDensity = configuration.fontScale * metrics.density;
          getBaseContext().getResources().updateConfiguration(configuration, metrics);
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_app_main);
          adjustFontScale(getResources().getConfiguration());
          this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  
          BottomNavigationView bottomNavigationView = findViewById(R.id.navigation_bar);
          bottomNavigationView.setOnNavigationItemSelectedListener(navigationItemSelectedListener);
  
          getSupportFragmentManager().beginTransaction().replace(R.id.fragments_container, new HomeFragment()).commit();
      }
  
      private BottomNavigationView.OnNavigationItemSelectedListener navigationItemSelectedListener =
              new BottomNavigationView.OnNavigationItemSelectedListener() {
                  @Override
                  public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                      Fragment selectedFragment = null;
  
                      switch (menuItem.getItemId()){
                          case R.id.nav_home:
                              selectedFragment = new HomeFragment();
                              break;
                          case R.id.nav_orders:
                              selectedFragment = new MyOrdersFragment();
                              break;
                          case R.id.nav_feedback:
                              selectedFragment = new FeedbackFragment();
                              break;
                          case R.id.nav_profile:
                              selectedFragment = new MyProfileFragment();
                              break;
                      }
  
                      getSupportFragmentManager().beginTransaction().replace(R.id.fragments_container,selectedFragment).commit();
                      return true;
                  }
              };
  }
  </code></pre>
  
  <p>I looked for a similar question like this but none of them have been answered</p>
  
  <p>Edit: Issue only appears when i press from back to front but when i'm going from 1-4 the issue doesn't arise but when i click suddenly from 4 to any other tab the bar gets pushed down.</p>