Android: how to set the height/width of the src image of a ImageButton?

George_BJ picture George_BJ · Nov 17, 2011 · Viewed 59k times · Source

Android: how to set the height/width of the image(src image intead of the background) of a ImageButton?

I want to set the height/width of the top level image(not the background) image, the size of image should be customized instead of fullfill the button automatically

Answer

user3426273 picture user3426273 · Apr 15, 2014

You can just Use the scaleType attribute of ImageButton. Set it to fitXY or fitCenter or anything else according to your need.

like this

<ImageButton
    android:id="@+id/imageButton"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:scaleType="fitCenter"
    android:src="@drawable/some_image">
</ImageButton>