Trying to center mini FAB above normal FAB

Viewed 31

I'm trying to center a mini fab button above a normal one using ConstraintLayout. However, it will be ultimately skewed one way. Here's the XML code:

<?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:id="@+id/constraintLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    tools:context=".MainActivity">


    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab_task"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginBottom="24dp"
        app:backgroundTint="@color/fab_event"
        app:fabSize="mini"
        app:layout_constraintBottom_toTopOf="@+id/fab_plus"
        app:layout_constraintEnd_toEndOf="@+id/fab_plus"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="@+id/fab_plus"
        app:srcCompat="@drawable/ic_baseline_task_alt_24"
        app:tint="@color/white" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab_plus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:srcCompat="@drawable/ic_baseline_add_24" />

</androidx.constraintlayout.widget.ConstraintLayout>

This is how it looks.

The selection squares around the buttons aren't also centered which I think is why the main issue is happening.

Can anything be done about this?

0 Answers
Related