Imagebutton set image size

So, imagine that your layouts have a few buttons. The project is almost finished, and there is a lot of dynamic material (software settings for images, listeners, declared lines, etc. Etc.).

Now you are told that the buttons are pretty hard to click so that your first thought (at least mine) is “okay, I'll just make the bounding box larger.” To do this, I just need to give these buttons more width and height to make them easier to click.

My problem arises when I see that these buttons use the background to store the image, and therefore, when I make them bigger, so the image is inside.

My question is: I got stuck in creating a layout on top of it, assigned the listener this new, larger layout, and then left the button as an image, or is there an easier way?

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

thank

+5
source share
3 answers

Nevermind, found the answer, I'll just leave it here if anyone else has this problem.

In our case, we could not afford to edit the images, what I did was change the node button to ImageButton. Now, instead of using the background, we use src and, as soon as the ImageButton is enlarged, a simple internal addition will be added, so the image maintains its original size, even if the button itself is actually larger and therefore easier to click.

, , :

android:background="@null"
+1

xml

android:background="@null"

+1

Edit all your buttons and set layout_marginor paddingto the desired space.

Example:

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="20dp"
    android:padding="20dp"
    android:text="Button" />
0
source

All Articles