Android material design specifications have the default icon size of floating action button in android as 24 x 24 dp.
There are cases when you will like to add icon with a different size to Android FAB button.
You will soon realized that the icon might be too small or placed out of position.
A good way to learn how to resize floating action button in android is making use of the scaleType
property.
The values of scaleType
attribute are – center, centerCrop, centerInside, fitCenter, fitEnd, fitStart, fitXY and matrix
.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:gravity="center" android:orientation="vertical"> <android.support.design.widget.FloatingActionButton android:id="@+id/floatingActionButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerCrop" app:srcCompat="@android:drawable/btn_dialog" /> </LinearLayout>
In the next code snippet, you will learn different ways you can use to increase the size of android floating action button in android.