Android: scaling a button with a background image.
Posted
by jkhouw1
on Stack Overflow
See other posts from Stack Overflow
or by jkhouw1
Published on 2010-05-14T19:39:59Z
Indexed on
2010/05/14
19:44 UTC
Read the original article
Hit count: 273
I'm probably just being daft but my Google searches are not working out well.
I have a bunch of buttons i add in code that all have dynamic text. I've set a background image for each of these buttons since the default greybutton doesn't work well for my application.
This works perfectly and when the text size (or content) changes, the button automatically grows to accommodate the expanded text. What doesn't work is that I'd like the button to scale proportionally - i.e. if the background image is round, i'd like it to stay round rather than oval as the button gets bigger.
With an imagebutton, there is a property "Adjust view bounds" that does exactly this but I cant put text on an imagebutton. Is there something equivalent for a regular button?
or am I going about this wrong?
i also tried setting the width of the button in code, but I can't seem to determine the new height (button.getHeight() returns 0)
© Stack Overflow or respective owner