Bottomnavigationview is not at the bottom of the screen

Asked

Viewed 137 times

0

I am with a problem is a layout I am developing, this is my Activity for customer registration and I have only in it a Bottomnavigationview, and a Linearlayout that I will replace with a Fragment

  • Activitycadastrocliente

    <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>
    

  • Fragmentacadastrocliente

inserir a descrição da imagem aqui

  • Customer registration.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 I need to do to fix my Layout to appear my Bottomnavigationview at the bottom of the screen?

1 answer

1


I think it’s because you’re replacing the contents of LinearLayout adding a Fragment to it. This sort of removes your content, which in this case is the Bottomnavigationview.

Use a Relativelayout as root and your problem 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 added two new attributes, which are: layout_alignParentBottom and layout_above.

The first causes the Bottomnavigationview align to the bottom of the root layout, which is the very Relativelayout.

The second causes the Fragment layout to be aligned above the Bottomnavigationview, but this makes the items stay cut. However, if you want to put items under Bottomnavigationview, you can remove the attribute and use the view Space in the layout of your Fragment. That view Space needs to be the same size (height) of Bottomnavigationview, otherwise, the last items of scroll will be cut/invisible.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.