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
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.
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".
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.
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" />
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
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" />
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
You can use NinePatchDrawable... A resizeable bitmap, with stretchable areas that you define.
http://developer.android.com/reference/android/graphics/drawable/NinePatchDrawable.html
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 .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With