Bottom Navigation Bar , FloatingActionButton & layout_anchor not working

59 views Asked by At

I'm trying to create a Bottom Navigation Bar with FloatingActionButton like this: enter image description here

But my result is different:

enter image description here .

Why is this the result? Attach the XML file:

<androidx.coordinatorlayout.widget.CoordinatorLayout 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">


    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">


        <FrameLayout
            android:id="@+id/nav_host_fragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="?attr/actionBarSize"
            app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
            />


        <com.google.android.material.bottomappbar.BottomAppBar
            android:id="@+id/bottomAppBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:contentInsetEnd="0dp"
            app:contentInsetStart="0dp"
            app:elevation="0dp"
            app:fabAlignmentMode="center"
            app:fabAnimationMode="scale"
            app:fabCradleMargin="10dp"
            app:fabCradleRoundedCornerRadius="25dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <com.google.android.material.bottomnavigation.BottomNavigationView
                android:id="@+id/bottomNavigationView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:labelVisibilityMode="labeled"
                app:menu="@menu/bottom_menu" />


        </com.google.android.material.bottomappbar.BottomAppBar>


        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:contentDescription="@string/app_name"
            android:src="@drawable/baseline_rocket_24"
            app:backgroundTint="@color/blue"
            app:elevation="5dp"
            app:fabSize="normal"
            app:layout_anchor="@id/bottomAppBar" />


    </androidx.coordinatorlayout.widget.CoordinatorLayout>


</androidx. coordinator layout.widget.CoordinatorLayout>

These are the dependencies :

dependencies {

    implementation("androidx.appcompat:appcompat:1.6.1")
    implementation("com.google.android.material:material:1.9.0")
    implementation("androidx.constraintlayout:constraintlayout:2.1.4")
    implementation("com.google.firebase:firebase-database:20.2.2")
    implementation("com.google.firebase:firebase-auth:22.1.2")
    implementation("com.google.firebase:firebase-auth-ktx:22.1.2")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("com.google.android.material:material:1.3.0-alpha03")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
    implementation("androidx.compose.material:material:1.6.0-alpha07")
    implementation(platform("com.google.firebase:firebase-bom:32.3.1"))
    implementation("com.google.firebase:firebase-analytics")
}

The components don't seem to connect together and just rest on top of each other. So far I haven't found the reason why it doesn't work, so I'm asking you for help.

0

There are 0 answers