Reputation:
My layout includes this ImageButton as shown:
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?
Upvotes: 0
Views: 1151
Reputation: 12191
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"
Upvotes: 3
Reputation: 796
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"/>
Upvotes: 1
Reputation: 5371
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"/>
Upvotes: 0