Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stretch the image in imagebutton to the whole area of the imagebutton?

Here is a picture that will help you understand my problem:

It's a "1"

I want to stretch the image shown inside ImageButton to the whole area of the ImageButton. As you can see, the picture with the number 1 only take about 95% of the ImageButton and you can also see the boundaries of the ImageButton.

I still want to maintain the image button style

Here's how I am using ImageView:

<ImageButton
    android:id="@+id/secondActivityBbuttonDownRight"
    android:layout_width="0dip"
    android:layout_height="match_parent"
    android:layout_weight="0.5"
    android:scaleType="fitStart"
    android:src="@drawable/111" />

I think I found out what is my problem. I need a custom component that can contain only an image and have a clicking effect.

like image 432
user2051993 Avatar asked Sep 10 '25 04:09

user2051993


2 Answers

ImageButton is ImageView.
If you want your image to fill button
than set android:scaleType="fitXY", so the image you set in android:src will be stretched to fill whole image button.

ImageButton has a background under your image and padding.
If you do not want background
set android:background="@android:color/transparent".
If you do not want padding
set android:padding="0" or set background without padding.

like image 98
Leonidos Avatar answered Sep 12 '25 20:09

Leonidos


You can also use

android:scaleType="centerCrop"
android:padding="0dp"
like image 45
zackygaurav Avatar answered Sep 12 '25 20:09

zackygaurav