Button top increase with multiple lines
- by NeTeInStEiN
Some very very strange behaviour was appearing in my Android application.
I was extending Button to replace the standard. In my own button I set:
- TextAppearence (text 16px, bold..)
- BackgroundDrawable (to an selector that replaced the standard button, that used images of 60px)
- Gravity: LEFT|CENTER_VERTICAL.
Whenever the text was enough to make the button have 2 text lines, if it had the property Gravity.CENTER_VERTICAL, a top padding would appear!
This kept me overflowing and googling for weeks... (set paddingTop, singleLine, and other simple solutions didn't work of course!)
Finally got the solution!!!
@Override
protected boolean setFrame(int l, int t, int r, int b) {
int fixedTopSize = 5;
return super.setFrame(l,fixedTopSize, r, b-t);
}
By overriding this method on the extended Button finally i got it to work without the irritating top padding... still i don't understand why this happens.
Any ideia?