Button top increase with multiple lines
Posted
by
NeTeInStEiN
on Stack Overflow
See other posts from Stack Overflow
or by NeTeInStEiN
Published on 2010-12-30T00:40:22Z
Indexed on
2010/12/30
0:54 UTC
Read the original article
Hit count: 98
android
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?
© Stack Overflow or respective owner