Android: Floating Button Icon is not centred

后端 未结 9 2341
忘了有多久
忘了有多久 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:19

    You should set fabCustomSize value like FAB exactly size:

    <android.support.design.widget.FloatingActionButton
            android:layout_width="60dp"
            android:layout_height="60dp"
            app:fabCustomSize="60dp"
            android:src="@drawable/plus_icon"
            app:rippleColor="@color/colorPrimaryDark" />
    
    0 讨论(0)
  • 2020-12-10 01:21

    Best solution is not to hardcode the FAB's dimension.

    Icon will be centered with attribute android:scaleType="center"

    <android.support.design.widget.FloatingActionButton
                    android:id="@+id/search_fab"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:scaleType="center"
                    android:layout_marginEnd="10dp"
                    android:src="@drawable/fab_search_icon"
                    app:backgroundTint="@color/colorPrimary"
                    app:elevation="4dp"
                    app:fabSize="normal"/>
    
    0 讨论(0)
  • 2020-12-10 01:22

    This usually arises when using custom-sized floating action button(FAB), because android by default, only supports 40dp FAB. The best way is to override it, by telling your view that you are using a custom sized FAB, and give the same size as value to it too.

    For example, while using a 60dp x 60dp FAB, this will do the trick.

    app:fabCustomSize="60dp"

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