Android: Floating Button Icon is not centred

后端 未结 9 2340
忘了有多久
忘了有多久 2020-12-10 00:53

I\'m trying to create a floating button in my app. The button is there, but the image in the button is a bit upwards (see image).

I can\'t figure out what\

相关标签:
9条回答
  • 2020-12-10 01:01

    Reason is your image is not in the right size!!

    Floating action button default circle size is 56 x 56dp , to get the best fit use that for your background image!!

    If you are going for a mini one should be : 40 x 40dp

    If you only want to change the Interior icon(only icon) use a 24 x 24dp icon for default size

    To test this again i download an image form internet and scaled it down to 56dp and kept a small space to balance it (i am no good with Photoshop)

    and added this to your FB view and made background yellow to make it clear.Let's see

    out put:

    This means it depends on the image that you add and its size if you want to go full background you can even use an imageButton

    Refer : https://material.io/guidelines/components/buttons-floating-action-button.html#buttons-floating-action-button-floating-action-button

    0 讨论(0)
  • 2020-12-10 01:04

    I have faced the same problem. the following solution have worked for me

    app:fabCustomSize="40dp"
    
    0 讨论(0)
  • 2020-12-10 01:05

    Use (https://github.com/futuresimple/android-floating-action-button) and set fab:fab_icon="@drawable/ic_fab_star" to center icon

    0 讨论(0)
  • 2020-12-10 01:09

    You have to add only app:fabCustomSize="40dp" it's work for me

    0 讨论(0)
  • 2020-12-10 01:11

    I just set the app:fabCustomSize=”40dp” (needed size) and I set the height and width as wrap_content then issue solved

    0 讨论(0)
  • 2020-12-10 01:16

    Try to do to fix your height and width...

        android:layout_width="50dp"
        android:layout_height="50dp"
    

    and please adjust your layout in bottom another way ..bacause here yo do

     android:layout_marginTop="480dp" 
    

    it is not a proper way my suggestion try to set your FloatingActionButton inside Relative Layout..and set like this property..

        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
    
    0 讨论(0)
提交回复
热议问题