Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Floating action button layout anchor not working in my code

the app:layout_anchor not working

I want a floating action button in between my two relative layouts.

For this I have taken parent layout as coordinator layout and specified the anchor and anchor gravity to fab button.

But its not getting set where I want it to be.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

i want to put the fab on the middle of the Bottom Navigation Bar

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Home">

    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        app:fabCradleMargin="10dp"
        app:fabCradleRoundedCornerRadius="10dp"
        app:fabCradleVerticalOffset="10dp"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="674dp"
        tools:ignore="BottomAppBar,MissingConstraints">

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bottomNavigationView"
            android:layout_marginRight="16dp"
            app:menu="@menu/bottom_nav_menu"
            android:background="@drawable/transparent_background" >
        </com.google.android.material.bottomnavigation.BottomNavigationView>

    </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:src="@drawable/baseline_add_24"
        app:layout_anchor="@id/bottomAppBar"
        tools:ignore="MissingConstraints"
        />

</androidx.constraintlayout.widget.ConstraintLayout>


**i try to change the gradle material version but that doesn’t work **

>Solution :

You have used androidx.constraintlayout.widget.ConstraintLayout and that’s why app:layout_anchor is not working . Kindly replace androidx.constraintlayout.widget.ConstraintLayout with Coordinatorlayout

For more details , visit this link and example

https://developer.android.com/jetpack/androidx/releases/coordinatorlayout

FloatingActionButton, layout_anchor and layout_gravity

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading