Android Design Library - Floating Action Button Padding/Margin Issues

后端 未结 7 2193
梦毁少年i
梦毁少年i 2020-12-02 05:14

I\'m using the new FloatingActionButton from the Google Design Library and I am getting some strange padding/margin problems. This image (with developer layout options on) i

7条回答
  •  攒了一身酷
    2020-12-02 06:16

    Update (Oct 2016):

    The correct solution now is to put app:useCompatPadding="true" into your FloatingActionButton. This will make the padding consistent between different API versions. However, this still seems to make the default margins off by a little bit, so you may need to adjust those. But at least there's no further need for API-specific styles.

    Previous answer:

    You can accomplish this easily using API-specific styles. In your normal values/styles.xml, put something like this:

    
    

    and then under values-v21/styles.xml, use this:

    
    

    and apply the style to your FloatingActionButton:

    
    

    As others have noted, in API <20, the button renders its own shadow, which adds to the overall logical width of the view, whereas in API >=20 it uses the new Elevation parameters which don't contribute to the view width.

提交回复
热议问题