0

enter image description here

    <com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/floatingActionButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:contentDescription="TODO"
    android:focusable="true"
    android:scaleType="fitCenter"
    app:backgroundTint="@color/black"
    app:fabSize="auto"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/checkBox6"
    app:maxImageSize="100dp"
    app:srcCompat="@drawable/add"
    app:tint="@color/blue" />

I want to make the picture center in Button, I tried to use constrained layout, but it didn't work in the inner of the FloatingActionButton. I chang my code but it didn't work.

    <com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/floatingActionButton2"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_marginEnd="30dp"
    android:layout_marginRight="30dp"
    android:layout_marginBottom="60dp"
    android:clickable="true"
    app:backgroundTint="#000000"
    app:fabCustomSize="50dp"
    app:elevation="0dp"
    app:borderWidth="0dp"
    app:fabSize="normal"
    app:pressedTranslationZ="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:maxImageSize="100dp"
    app:srcCompat="@drawable/add"
    app:tint="@color/blue" />

<com.google.android.material.floatingactionbutton.FloatingActionButton

enter image description here

Liu Peng
  • 11
  • 4
  • Does this answer your question? [How to center image in FloatingActionButton behind transparent background?](https://stackoverflow.com/questions/44122004/how-to-center-image-in-floatingactionbutton-behind-transparent-background) – Anand Jun 04 '21 at 02:05
  • I changed my code, but it didn't work. – Liu Peng Jun 04 '21 at 04:22

2 Answers2

0
<com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            app:backgroundTint="@color/colortoolbar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/fab_margin"
            app:srcCompat="@drawable/world"
            app:fabSize="mini"/>

You are giving different margin sizes.remove them.

Krishan Madushanka
  • 319
  • 1
  • 5
  • 21
0

The final code is

    <com.google.android.material.floatingactionbutton.FloatingActionButton
    android:id="@+id/floatingActionButton2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="32dp"
    android:layout_marginRight="32dp"
    android:layout_marginBottom="40dp"
    android:clickable="true"
    app:backgroundTint="#FFFFFF"
    app:fabSize="mini"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:maxImageSize="91dp"
    app:srcCompat="@drawable/add"
    app:tint="@color/blue" />

enter image description here

Liu Peng
  • 11
  • 4