The red square is the button's boundary, while the image remains centered at 32x32px. I've tried using button.getImage() to set position and size to the button's values, but it doesn't seem to have any effect.
Just use a regular Button
. It also contains a Drawable
for its background, but that one is always stretched to fill the button. See the JavaDoc for ImageButton
:
... If the image is the size of the button, a Button without any children can be used, where the
Button.ButtonStyle.up
,Button.ButtonStyle.down
, andButton.ButtonStyle.checked
nine patches define the image.
Note that these don't actually need to be nine patches; any Drawable
will do.
Probably super late but have you tried:
yourButton.getImage().setFillParent(true);
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