BottomNavigationView is not at the bottom of the screen

1

I have a problem with a layout that I'm developing, this is my activity for client registration and I only have a BottomNavigationView, and a LinearLayout that I'll replace with a

  • ActivityCadastroCustomer

        

    <LinearLayout
        android:id="@+id/fragment_trocar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
    
        <android.support.design.widget.BottomNavigationView
            android:id="@+id/bottomNavigatintoonCadastroCliente"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@drawable/custom_button_line"
            android:elevation="8dp"
            app:itemIconTint="@color/colorBlack"
            app:itemTextColor="@color/colorBlack"
            app:menu="@menu/menu_bottom_cadastro_cliente" />
    </LinearLayout>
    

  • FragmentCadastroCustomer

  • CadastroClienteActivity.java

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cadastro_cliente);
    
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment_trocar, new CadastroClienteFragment());
        fragmentTransaction.commit();
    }
    
    public void iniciarComponentes() {
        bottomNavigatintoonCadastroCliente = (BottomNavigationView) findViewById(R.id.bottomNavigatintoonCadastroCliente);
    }
    

    }

What do I need to do to fix my Layout to show up my BottomNavigationView at the bottom of the screen?

    
asked by anonymous 07.12.2017 / 14:44

1 answer

2

I think it's because you're replacing the contents of LinearLayout by adding a fragment to it. This will remove your content, which in this case is BottomNavigationView .

Use RelativeLayout as root and your issue will be solved.

<RelativeLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/fragment_trocar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_above="@+id/bottomNavigatintoonCadastroCliente"/>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottomNavigatintoonCadastroCliente"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@drawable/custom_button_line"
        android:elevation="8dp"
        app:itemIconTint="@color/colorBlack"
        app:itemTextColor="@color/colorBlack"
        app:menu="@menu/menu_bottom_cadastro_cliente" />
</RelativeLayout>

This should work normally. One more thing: I've added two new attributes, which are: layout_alignParentBottom and layout_above .

The first causes the BottomNavigationView to align to the bottom of the root layout , which is RelativeLayout itself.

>

The second causes the fragment layout to be aligned above the BottomNavigationView , but this causes the items to be cut off. However, if you want to place the items under the BottomNavigationView, you can remove the attribute and use the Space view in your fragment layout. This Space view must be the same size ( height ) of BottomNavigationView , otherwise the last scroll items will be cut / invisible .

    
07.12.2017 / 15:14