#5 Daily issues Android-Floating Action Button Icon not aligned centre

Issue:

Arun Pandian M
1 min readMar 9, 2019

When I am trying to set the height and width value instead of wrap_content to FAB, the FAB icon not aligned to centre.

//In this code, Icon not aligned
<android.support.design.widget.FloatingActionButton
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/ic_add_white_24dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="28dp"
android:backgroundTint="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

My Proposed Solution:

I just set the app:fabCustomSize=”40dp” (needed size) and I set the height and width as wrap_content then issue solved

<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabCustomSize="40dp"
android:src="@drawable/ic_add_white_24dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="28dp"
android:backgroundTint="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

If you have any better solution than this, please let me know. Happy Coding and Have a fun…

--

--

Arun Pandian M

Senior Android developer at FundsIndia, A time investor to learn new things about Programming. Currently in a relationship with Green Bug(Android).