TAGS :Viewed: 4 - Published at: a few seconds ago

[ Android ImageButton Layout ]

Hi everyone I want to create an image button in android but the image that I want to import for that image button it doesn't fit the buttons layout. Anyone knows how could I make the image to fit the buttons width and height ? So basically the buttons width and height out scales my images width and scale.Many thanks in advance.!

My code: (from comment)

<ImageButton 
   android:id="@+id/imageButton1"
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:layout_alignParentRight="true" 
   android:layout_alignParentTop="true" 
   android:src="@drawable/imagebtn2" 
   android:scaleType="fitXY"/>

Answer 1


You'll have to use a different scaleType on your ImageButton.

Refer to this for a list of possible ScaleTypes: http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

You can set the ScaleType in the xml like this:

<ImageButton
 ....
 android:scaleType="center"
 ....

Answer 2


if you want to put image as button then you have to resize the size of the images which you are planning to put as buttons.

android supports different types of layouts such as hdpi,ldpi,mdpi,xhdpi and xxhdpi in which the resolutions of the screen changes accordingly.

[Here is link to resize the images HERE

after you save the images of different sizes it is supposed to put in respected drawable folders of respected project.