Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android imagebutton how to change icon size

I have been working on interfaces lately and I have many problems with imagebutton sizes. I'm very bad at designing stuff and I'm having major problems with the Android Icons. Thus, I have some questions regarding those.

First of all this is my current layout:

enter image description here

As you can see, I have two icons that have different sizes and that's not good. I can't seem to force them to take the same size.

My questions are:

1 - How do I force them to take the same size?

2 - What are the recommended size differences for hdpi, ldpi,mdpi and xhdpi?

3 - Why, if I set the imageButton background color to the same color as the layout background, the Icon is moved as if there was no button in the background?

Example: enter image description here

Thanks in advance!!

like image 527
Loic O. Avatar asked Jul 18 '12 09:07

Loic O.


People also ask

How do I increase the size of my fab button?

If you want to set icon size to particular Floating Action Button just go with Floating action button attributes like app:fabSize="normal" and android:scaleType="center".

How do I change the icon size on my floating action button?

The Best Answer is. As your content is 24dp x 24dp you should use 24dp icon. And then set android:scaleType="center" in your ImageButton to avoid auto resize.

How do you make a picture fit in ImageButton?

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. However, it is much easier to set and preview in xml in my opinion.

What is android ImageButton?

An ImageButton is an AbsoluteLayout which enables you to specify the exact location of its children. This shows a button with an image (instead of text) that can be pressed or clicked by the user.


2 Answers

For these ImageButtons set the images using (instead of src):

android:background="@drawable/image_name"

Next thing is set:

android:layout_height="10dp" //or any size required
android:layout_width="10dp" //or any size required ... let these 2 sizes be same for both the ImageButtons

"dp" or "dip" is device independent pixels. The android system will take care of the resizing for different screen resolutions

Also, a better thing to do would be to set-up hover images for your button separately.

like image 70
pixelscreen Avatar answered Sep 21 '22 09:09

pixelscreen


Instead of replacing android:src with android:background you can use android:scaleType attribute and set it to "fitXY".

see: Android - Image Button Scale

like image 23
muiz6 Avatar answered Sep 23 '22 09:09

muiz6