Changing floating button image size programmatically

后端 未结 1 1455
感动是毒
感动是毒 2021-01-21 21:59

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

I tried different scale types but it did\'t work.

1条回答
  •  北荒
    北荒 (楼主)
    2021-01-21 22:29

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

    
    

    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.

    0 讨论(0)
提交回复
热议问题