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's wrong with it. Below is part of the XML for floating button.
<android.support.design.widget.FloatingActionButton android:id="@+id/buttonUp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="16dp" android:layout_marginTop="480dp" android:clickable="true" android:scaleType="center" android:src="@drawable/btn_back_to_top_3x" app:layout_anchor="@id/layout" app:layout_anchorGravity="bottom|right|end" app:backgroundTint="@android:color/background_light" app:fabSize="normal" />
The button is showing where I wanted it. The only problem seems to be the image inside isn't center. Why is this happening?
EDIT: After some more looking around I realized the image itself was having problem where the image isn't actually centered and there are space at the bottom side (which cause the image to being push upward).
Add the floating action button to your layoutThe size of the FAB, using the app:fabSize attribute or the setSize() method. The ripple color of the FAB, using the app:rippleColor attribute or the setRippleColor() method. The FAB icon, using the android:src attribute or the setImageDrawable() method.
To change the shape of the Floating action button: You can use the shape property of FloatingActionButton() widget class. Implement BeveledRectangleBorder( ) on this property. The output will be a square floating action button, increase the border-radius value to make a circular type shape.
A floating action button (FAB) performs the primary, or most common, action on a screen. It appears in front of all screen content, typically as a circular shape with an icon in its center.
I have faced the same problem. the following solution have worked for me
app:fabCustomSize="40dp"
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With