FAB 位于底部导航之上

FAB on top of Bottom Navigation

如何在底部导航顶部显示工厂?这是我试过的:

<com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="@+id/trendingPosts"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/trendingPosts"
        android:focusedByDefault="true"
        android:focusable="true"/>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_menu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="@+id/trendingPosts"
        app:layout_constraintTop_toBottomOf="@+id/trendingPosts"
        app:menu="@menu/main_menu"
        android:focusable="false"
        android:focusedByDefault="false"/>

但是,晶圆厂仍低于它。见图:

您需要使用协调器布局

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            
            <com.google.android.material.bottomnavigation.BottomNavigationView
                android:id="@+id/bottom_menu"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="@+id/trendingPosts"
                app:layout_constraintTop_toBottomOf="@+id/trendingPosts"
                app:menu="@menu/main_menu"
                android:focusable="false"
                android:focusedByDefault="false"/>

        </androidx.constraintlayout.widget.ConstraintLayout>

       <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="32dp"
            android:layout_gravity="bottom|center"
            android:focusedByDefault="true"
            android:focusable="true"/>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>