androidfloating-action-buttonbottomnavigationviewandroid-bottomappbar

My floating action button is not displayed properly...?


I am using TAB LAYOUT with View Pager and a BOTTOM APP BAR with a Floating Action Button for Bottom Navigation but i think my floating action button is being displayed under view pager so its looking like its being cut from above....please help me fix this

Here is my XML Code....

<androidx.constraintlayout.widget.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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/ic_main_bg"
    tools:context=".home.HomeActivity">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:id="@+id/coordinator_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent">

        <com.google.android.material.bottomappbar.BottomAppBar
            android:id="@+id/bottomAppBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/bottom_navigation_bg"
            app:fabCradleRoundedCornerRadius="0dp"
            app:backgroundTint="@color/color_primary"
            />

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/floatingActionButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:backgroundTint="@color/color_primary"
            app:srcCompat="@drawable/ic_plus"
            app:layout_anchor="@id/bottomAppBar"
            android:contentDescription="@string/add_item_to_this_destination" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/color_primary"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:tabIndicatorColor="@color/color_secondary"
        app:tabSelectedTextColor="@color/color_secondary"
        app:tabTextColor="@color/color_secondary" />

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/view_pager_2"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/coordinator_layout"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tab_layout">

    </androidx.viewpager2.widget.ViewPager2>

</androidx.constraintlayout.widget.ConstraintLayout>

and here is what it looks like

enter image description


Solution

  • The issue is because of CoordinatorLayout

    Solution 1: Add

    android:clipToPadding="false"
    android:clipChildren="false"
    

    in CoordinatorLayout

    Solution 2: Make CoordinatorLayout as parent layout and put all child layout in it.

    Solution 3:

    In view_pager_2 add

                android:layout_marginBottom="?actionBarSize"
    

    Solution 4: Add this line to your fab

    android:elevation="10dp"