Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imagebutton set image size

So imagine you have several Buttons on your layouts. The project is almost finished and there's a lot of dynamic stuff (programmatically setting images, listeners, statedrawables, etc. etc.).

Now, you're told that the buttons are kinda tricky to click so your first thought (at least mine) is "ok, I'll just make the bounding box bigger". To do this, I just need to give those Buttons more width and height so they will be easier to click.

My problem comes when I see that those Buttons are using background to store the image and so, whenever I make them bigger so does the image inside.

My question is, am I stuck with having to create a layout on top of it, assign the listener to this new, bigger layout, and then leaving the button as an image, or is there any easier way?

                                             /¯¯¯¯¯¯¯¯¯¯¯¯\ <- outter layout
                   /¯¯¯¯¯¯¯¯\                | /¯¯¯¯¯¯¯¯\ |
                   |        |                | |        | |
                   | BUTTON |      --->      | | BUTTON | |
                   |        |                | |        | |
                   \________/                | \________/ |
                                             \____________/

Thanks

like image 320
h4lc0n Avatar asked Nov 04 '22 05:11

h4lc0n


2 Answers

Nevermind, found the answer, I'll just leave it here in case anyone else is having this issue.

In our case we couldn't afford to edit the images, what I did is change the Button node to an ImageButton. Now, instead of using background we use src and, once the ImageButton is enlarged, a simple inside-padding is added so the image maintains the original size even though the button itself is actually bigger and, therefore, easier to click.

On a side note, if your previous background had alpha you might want to do this now:

android:background="@null"
like image 158
h4lc0n Avatar answered Nov 08 '22 05:11

h4lc0n


Use this in your xml layout

android:background="@null"

This will help you to show you button as the image only

like image 24
edwin Avatar answered Nov 08 '22 04:11

edwin