Skip to content Skip to sidebar Skip to footer

Remove Padding Of Imagebutton

How can I get an ImageButton that has a fixed height and is only as wide as it needs according to the ratio of its source image? I tried the following:

Solution 1:

It's because you've set a limited height. That limits the image height, but when Android calculates the width of the content (the original unrezised image), it's wider.

You'll get the image without the black "padding" on the side if you use wrap_content for the height as well.

<ImageButton
android:layout_width="wrap_content"android:layout_height="wrap_content"android:minWidth="0pt"android:scaleType="fitCenter"android:adjustViewBounds="true"android:src="@drawable/list_download"android:background="@android:color/black"android:padding="0pt"/>

So, if you want the picture to be a specific size, you could resize it in your drawable folder to the size you want.

Solution 2:

you just need use android:scaleType="fitXY" and set padding 0dp.

<ImageButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:scaleType="fitXY"android:padding="0dp"/>

Solution 3:

you can put it in a Frame like so :

<FrameLayoutandroid:layout_width="wrap_content"android:background="@android:color/black"android:layout_height="wrap_content"><ImageViewandroid:src="@drawable/list_download"android:scaleType="fitCenter"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_width="8dp"/></FrameLayout>

it will be much easier to play with it like so

Post a Comment for "Remove Padding Of Imagebutton"