Android studio 如何让图片在 FloatingActionButton 居中
In Android studio how to let a image in FloatingActionButton center
<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" />
我想让Button中的图片居中,我试过用constrained layout,但是在FloatingActionButton里面不行。
我更改了我的代码,但没有用。
<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
<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"/>
你给了他们不同的保证金sizes.remove。
最终代码为
<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" />
<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" />
我想让Button中的图片居中,我试过用constrained layout,但是在FloatingActionButton里面不行。 我更改了我的代码,但没有用。
<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
<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"/>
你给了他们不同的保证金sizes.remove。
最终代码为
<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" />