Home » Android » android.support.design.widget.FloatingActionButton implenetation of FAB reduces image size

android.support.design.widget.FloatingActionButton implenetation of FAB reduces image size

Posted by: admin June 15, 2020 Leave a comment

Questions:

So I have started migrating to the official support design library for an Android app of mine, replacing elements as I go. I just replaced an FAB (implemented as ImageButton) with official android.support.design.widget.FloatingActionButton. But the icon inside the button is smaller as compared to the one it was in ImageButton. What may have been a reason?

FloatingActionButton‘s implementation:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/icon" />

Tried adding app:fabSize="normal but that didn’t work, either.

This is how it looks after using FloatingActionButton:

enter image description here

And this is how it looked like while using it as a ImageButton:

enter image description here

How to&Answers:

Set scale type to android:scaleType="center"

Answer:

Just a guess since you haven’t provided any details at all. The design library’s FloatingActionButton has padding calculations which will shrink the icon if it is too large, whereas your ImageButton probably just centers the icon with no scaling at all. I’m guessing that you would not observe this behavior if you were using a correctly sized 24dp icon, like the ones you get from: https://www.google.com/design/icons/.

Answer:

You can use : app:maxImageSize="..dp" to change the size of your icon!