Android: Create bigger Floating Action Button with bigger icon

前端 未结 8 515
陌清茗
陌清茗 2021-02-02 11:02

I want to create a bigger Floating Action Button (FAB), more than the usual 56 dp, with a bigger icon inside. (For my purpose an icon will never be self-explanatory so I will cr

8条回答
  •  [愿得一人]
    2021-02-02 11:42

    In the Android P preview, having the FAB match its parent's size stopped working for me, as the icon stopped scaling in size, making it much too small and way off-center.

    The easiest method I have found as a replacement is to place the FAB in a FrameLayout, set a fair margin on the FAB so the shadow is not cut off (I used 10dp), set both's sizes to wrap_content, and then add scaleX and scaleY to the FrameLayout.

    
    
        
    
    

    This works as expected, allows one to easily scale by specific amounts, and does not affect any other floating action buttons.

提交回复
热议问题