Проблема макета BottomNavigationView - PullRequest
0 голосов
/ 05 апреля 2019

Я использую BottomNavigationView с ConstraintLayout.Теперь проблема заключается в том, что, когда я нажимаю на второй элемент, все виды скрываются.

До щелчка

enter image description here

После щелчка

enter image description here

<android.support.constraint.ConstraintLayout 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/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="56dp"
        android:text="@string/title_home"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <LinearLayout
        android:id="@+id/linearLayout4"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:gravity="bottom"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">
    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="?android:attr/windowBackground"
        app:menu="@menu/navigation" />
    </LinearLayout>

</android.support.constraint.ConstraintLayout>

menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/navigation_home"
        android:icon="@mipmap/home_icon"
        android:title="@string/title_home" />

    <item
        android:id="@+id/navigation_dashboard"
        android:icon="@mipmap/my_order"
        android:title="My Order" />

    <item
        android:id="@+id/navigation_notifications"
        android:icon="@mipmap/home_earning"
        android:title="Earnings" />
    <item
        android:id="@+id/navigation_dashboard1"
        android:icon="@mipmap/cart_icon"
        android:title="Cart" />

    <item
        android:id="@+id/navigation_notifications2"
        android:icon="@mipmap/account_icon"
        android:title="Account" />


</menu>

Ответы [ 3 ]

1 голос
/ 05 апреля 2019

У меня была похожая проблема с ConstraintLayout.Вы можете попробовать это.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/container">

    <android.support.design.widget.BottomNavigationView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_gravity="bottom"
        android:background="@android:color/white"
        app:elevation="8dp"
        app:menu="@menu/navigation"
        android:layout_alignParentBottom="true">
    </android.support.design.widget.BottomNavigationView>

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:layout_above="@+id/bottom_navigation" />
</RelativeLayout>
1 голос
/ 05 апреля 2019

Я нашел проблему для этого, я установил в своем домашнем фрагменте android:fitsSystemWindows="true", я удалил ее, и она работает хорошо.

1 голос
/ 05 апреля 2019

Вам не нужно , чтобы иметь LinearLayout для этого.Используйте app:layout_constraintBottom_toBottomOf="parent" для перемещения navigation view вниз.

<android.support.constraint.ConstraintLayout 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/container"
                                             android:layout_width="match_parent"
                                             android:layout_height="match_parent">


    <android.support.design.widget.BottomNavigationView
            app:layout_constraintBottom_toBottomOf="parent"
            app:labelVisibilityMode="labeled"
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:menu="@menu/navigation_contractor" />

    <FrameLayout
            android:id="@+id/fragment_container"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="@string/title_home"
            app:layout_constraintBottom_toTopOf="@+id/navigation"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintVertical_bias="0.0"/>


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