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:
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:
Thanks in advance!!
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".
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.
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.
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.
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.
Instead of replacing android:src with android:background you can use android:scaleType attribute and set it to "fitXY".
see: Android - Image Button Scale
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