ImageButton 内的图像未缩放以填充按钮 [英] Image inside ImageButton not scaling to fill button
问题描述
我的布局包括这个 ImageButton,如图所示:
My layout includes this ImageButton as shown:
但是正如您所看到的,图像没有占据 ImageButton 的完整尺寸.
But as you can see, the image is not taking the full size of the ImageButton.
这是定义ImageButton的布局文件:
This is the layout file where the ImageButton is defined:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@mipmap/dashboard_profile"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="71dp"
android:layout_marginStart="71dp"
android:layout_marginTop="100dp"
android:id="@+id/imageButton3"
android:scaleType="fitXY"/>
如您所见,我已经添加了 android:scaleType="fitXY"
,但它不起作用.
As you can see, I already added android:scaleType="fitXY"
, but it's not working.
我也尝试在 Android Studio 的设计模式中更改按钮大小,但它不允许我更改.
I also tried to change the button size in Android Studio's design mode, but it's not letting me change.
我该如何解决这些问题?
How can I solve these problems?
推荐答案
与 Imageview 不同,Imagebutton 在图像区域周围有一个填充.这是故意的.这是因为默认按钮样式.您可以执行以下操作之一:
Unlike Imageview, Imagebutton has a padding around the image area. This is intentional. This is because of the default button style. You can do one of the following:
使用无边框按钮样式作为背景.
style="?android:attr/borderlessButtonStyle"
将背景设置为空.android:background="@null"
这篇关于ImageButton 内的图像未缩放以填充按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!