BottomNavigationView застрял наверху - PullRequest
0 голосов
/ 19 июня 2020

Я пытался заставить работать BottonNavigationView. Он просто остается в верхней части макета, и это сводит меня с ума. *https://material.io/develop/android/components/bottom-navigation/. Я даже попытался создать полностью чистый проект, где я попробовал, и произошло то же самое.

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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="wrap_content"
    android:orientation="vertical"
    tools:context=".MainActivity"
    android:id="@+id/mainLayout">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        app:menu="@menu/bottom_bar_menu" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/content"
        android:enabled="true"
        android:icon="@drawable/ic_menu_black_24dp"
        android:title="Content"/>
    <item
        android:id="@+id/document"
        android:enabled="true"
        android:icon="@drawable/ic_picture_as_pdf_black_24dp"
        android:title="Document"/>
    <item
        android:id="@+id/search"
        android:enabled="true"
        android:icon="@drawable/ic_search_black_24dp"
        android:title="Search"/>
</menu>

Снимок экрана

Есть идеи?

Ответы [ 2 ]

0 голосов
/ 19 июня 2020

Плотность вашей нижней навигации установлена ​​на начало android:layout_gravity="start" изменение ее на android:layout_gravity="bottom" должно работать для вас.

0 голосов
/ 19 июня 2020

Я хотел бы порекомендовать использовать ConstraintLayout и установить ограничения в Designer инструменте. Будет проще, если вы новичок в android мире.

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/mainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_bar_menu" />

</androidx.constraintlayout.widget.ConstraintLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...