4

I have floating button and image inside. And I need image to change size filling all space inside like here:|

enter image description here

I tried different scale types but it did't work. I got this result for now.

enter image description here

Finally I found the solution - maxImageSize. It worked, but now I need to set Fbutton size programmatically and I can't find the way to change maxImageSize in code.

1
  • Hi, same pb here - did you figure it out?
    – kevinob
    Commented Dec 12, 2020 at 12:21

1 Answer 1

-2

When you set the maxImageSize in the XML, you are changing the normal behavior and icon size of the FAB.

<com.google.android.material.floatingactionbutton.FloatingActionButton
            android:adjustViewBounds="true"
            android:id="@+id/fab_main"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:src="@drawable/ic_home"
            app:backgroundTint="@color/colorBottomAppBarFab"
            app:fabSize="normal"
            app:layout_anchor="@+id/bottom_app_bar"
            app:maxImageSize="56dp"/>

The result of this code is : FAB with image size 56dp

Later to change it again but programatically, you can use ScaleType to change the icon dimensions. Here an example in Kotlin:

fab_main.scaleType = ImageView.ScaleType.CENTER_INSIDE

And then, here is the new result: FAB with smaller icon size

If you want to change FAB dimensions, may be using one of the following methods can help you: FAB methods

I hope this solution can help you.

1
  • The question is how to do "app:maxImageSize" programmatically
    – Stav Bodik
    Commented Jan 8, 2021 at 8:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.