Android 带有自定义图像的Fab按钮

Android 带有自定义图像的Fab按钮,android,android-layout,floating-action-button,Android,Android Layout,Floating Action Button,我想将我的自定义图标添加到fab按钮, 我是这样指定的 <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_m

我想将我的自定义图标添加到fab按钮, 我是这样指定的

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@mipmap/ic_custom" />

它显示的图标,但没有完全填补晶圆厂,留下一些空白


我希望我的图标完全占据晶圆厂的大小和宽度(我的图标是圆形的)

浮动操作按钮将自动为图标添加填充。它不允许图像占据整个宽度/高度,这是对的

为此,创建一个带有阴影/立面的自定义圆形
ImageButton

一个简单的修复: 使用相对布局作为根布局。使用普通图像视图或按钮,将src设置为自定义图标和所需位置,而不是fab。假设您有一个id为“sv”的ScrollView,您希望在其上浮动按钮。只需使用上面的android:layout_=“@id/sv”,其中sv是您的滚动视图

<ImageView
android:id="@+id/floatingActionButton"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_above="@id/sv"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"

android:clickable="true"
android:onClick="edit"
android:padding="0dp"
android:scaleType="fitXY"
android:src="@drawable/ic_pen" />


dp中的图标大小是多少?我在所有res中都有图标
xhdpi
xxhdpi
xxxhdpi
您是否尝试过使用更大尺寸的图标?是的,图标大小是多少,它只是出现在中间,四周留有空白。您希望晶圆厂内的图标增大尺寸还是减小晶圆厂的尺寸<代码>应用程序:fabSize=“mini”将生成一个迷你晶圆厂。