0

In my Image Buttons, there is a lot of white space around the source image. Is it possible to remove this space so that the imagebutton just surrounds the source image itself.

enter image description here

<ImageButton
  android:id="@+id/story_1"
  android:src="@drawable/my_story"
  style="?android:attr/borderlessButtonStyle"
  android:layout_width="55dp"
  android:layout_height="wrap_content"
  android:adjustViewBounds="true"
  android:scaleType="fitXY"
  android:contentDescription="Add my story" />
walzhe
  • 31
  • 5
  • 1
    Is the white spaces in original image?, I mean like JPG images , see this also https://stackoverflow.com/questions/15116393/fit-image-in-imagebutton-in-android – Suhaib Raadan Jan 27 '21 at 21:48

3 Answers3

1

Try this

<ImageButton
  android:id="@+id/story_1"
  android:src="@drawable/my_story"
  style="?android:attr/borderlessButtonStyle"
  android:background="@null"
  android:layout_width="55dp"
  android:layout_height="wrap_content"
  android:adjustViewBounds="true"
  android:scaleType="fitXY"
  android:contentDescription="Add my story" />
rahat
  • 1,840
  • 11
  • 24
  • this works but I can no longer click the button (works like an imageview now) – walzhe Jan 28 '21 at 13:28
  • have you set onclick listener? and also `background` has nothing to do with click listener, may be button is too small, set height to at least `24dp` – rahat Jan 28 '21 at 13:29
  • 1
    Yeah my bad. The button was too small. It works! Thanks! – walzhe Jan 28 '21 at 13:33
0

Probably the problem caused by the image transparency. Try remove the white spaces around the image and make those areas transparent.

zarez
  • 65
  • 1
  • 9
0

make sure the original image you are using doesn't have too much white since you already have the solution in your xml scaleType="fitXY" you can try scaleType="fitCenter" but your image is already stretched to fit your entire button in the orginal code

Bilal Rammal
  • 814
  • 8
  • 14