Image inside ImageButton not scaling to fill button

1k Views Asked by At

My layout includes this ImageButton as shown:

You can see in this picture

But as you can see, the image is not taking the full size of the 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"/>

As you can see, I already added android:scaleType="fitXY", but it's not working.

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?

3

There are 3 best solutions below

2
On BEST ANSWER

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:

  • Use a borderless button style as your background.
    style="?android:attr/borderlessButtonStyle"

  • Set your background as null.
    android:background="@null"

1
On

Try to use android:src instead of app:srcCompat

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:src="@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"/>
0
On

You can use this code

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@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"/>