Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize ImageButton?

I want to resize my ImageButton using mouse on graphic layout or using code by android:layout_width , android:layout_height. But whenever I do this, the ImageButton isn't resized, in fact and it's not smaller but it is cut at the edges.

thanks in advance

like image 585
eng.ahmed Avatar asked Feb 11 '13 05:02

eng.ahmed


People also ask

How to scale an ImageButton android?

How to programatically resize and show them? Use a android:scaleType="fitCenter" to have Android scale the images, and android:adjustViewBounds="true" to have them adjust their bounds due to scaling. All of these attributes can be set in code on each ImageButton at runtime.

How do I reduce the size of the buttons on my pictures?

If you are using a png, you can move the image to a bigger background to get an even smaller image. For example, moving a 48x48 image in a 256x256 background to a 512x512 background will half its size in an ImageButton with android:scaleType="fitCenter".

What is an image button?

In Android, ImageButton is used to display a normal button with a custom image in a button. In simple words we can say, ImageButton is a button with an image that can be pressed or clicked by the users.


6 Answers

try setting android:background instead of android:src for setting the image on the button. That might help in your case, since it will stretch the image to your button's size. Also, you will have to specify fixed dimensions for the buttons (use dip instead of px). Example:

<ImageButton
     android:background="@drawable/ic_menu_more"
     android:layout_width="50dip"
     android:layout_height="50dip" />
like image 51
zrgiu Avatar answered Sep 28 '22 13:09

zrgiu


First try to use android:background instead of android:src for setting the image on the button.In most cases,it helps.If not,then see these..

  • ImageButton in Android
  • Resize ImageButton?
like image 43
ridoy Avatar answered Sep 27 '22 13:09

ridoy


    <ImageButton
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:background="@drawable/ic_star_border"
    />
or
       <ImageButton
            android:layout_width="36dp"
            android:layout_height="36dp"
            android:background="?selectableItemBackgroundBorderless"
            android:scaleType="fitXY"
            android:src="@drawable/ic_delete" />
like image 21
live-love Avatar answered Sep 28 '22 13:09

live-love


From steven-byle's solution (https://stackoverflow.com/a/15117536/1741997), he says:

"...Use an android:scaleType="fitCenter" to have Android scale the images, and android:adjustViewBounds="true" to have them adjust their bounds due to scaling..."

It works for me

like image 40
cesargastonec Avatar answered Sep 29 '22 13:09

cesargastonec


You can use NinePatchDrawable... A resizeable bitmap, with stretchable areas that you define.

http://developer.android.com/reference/android/graphics/drawable/NinePatchDrawable.html

like image 22
Brandon Frohbieter Avatar answered Sep 29 '22 13:09

Brandon Frohbieter


It might be the problem with size of your image..Try to use resized image then use it in your image button.Then you can set the width and height of the button .

like image 39
Payal Avatar answered Sep 27 '22 13:09

Payal