FloatingActionButton icon indicating copy to clipboard operation
FloatingActionButton copied to clipboard

added new fab_size property for custom size requirements

Open sfunke opened this issue 9 years ago • 4 comments

  • new fab_size xml attribute
  • allows for setting custom size (sometimes it's an requirement)
  • if omitted, default values will be used

sfunke avatar Feb 25 '15 07:02 sfunke

This is how it looks with a custom FAB size set to 42dp on the pre-Lollipop device:

device-2015-03-14-133625

The white outline exists around the button because shadow is used as an image asset of a constant size. I had to adapt this shadow image to fully match two standard sizes but it's not stretched to custom size.

So as long as we use shadow as an image, it's not possible to set a custom FAB size (with shadow). But I assume we can somehow generate a shadow in the runtime. I will invesigate this possibility.

makovkastar avatar Mar 14 '15 11:03 makovkastar

Aha, yes you are right, I think I tested it but may have missed to test it with sizes smaller than default.

What do you think about constraining the size not to be smaller than the smallest default size? (48dp, I guess?) I think there may be the requirement for larger buttons, but not so much for smaller ones.

Regarding generating runtime shadows, I did some experiments for custom dropshadows in another projects, basically black-painting the object, blur it, and draw it underneath the object. So this could work as well, although potential affections on performance should be considered.

If you don't mind I'll have a look into it as soon as I have time.

Thanks for the hint!

sfunke avatar Mar 14 '15 12:03 sfunke

@sfunke Did you have time to look into this again?

MGaetan89 avatar Apr 14 '15 12:04 MGaetan89

@MGaetan89 Yes, I just added a fix on my fork, hopefully it gets pulled in. It's true that it's a bit whacky on pre-Lollipop devices to get the shadow straight. The current workaround is that the fixed size shadow drawable gets stretched accordingly (depending on the size), plus taking the shadow margin into account.

Also I decided, that when fab_type="mini" is explicitly set, I ignore the fab_size property (so that FAB is shown in normal "mini" appearance, and it just gets it's "mini"-shadow applied.)

It's been tested on Lollipop & pre-Lollipop, as well with larger & smaller FAB-sizes, and on different resolutions.

@makovkastar What do you think?

sfunke avatar Apr 15 '15 08:04 sfunke