Searching how to reduce the padding inside my buttons, I found out in https://stackoverflow.com/a/20323723/3888000 that I should set the min-height of my button to 0dp in the xml file. And yes, it works for me.
Problem is : I want to create my button programmatically, and neither setMinimumHeight(1) nor setMinHeight(1) did work. How to do it ?
By the way, what is the difference between these two methods ?
Thank you !
I think you should try using setPadding(0,0,0,0); instead and see if that works for you.
As far as minHeight vs minimumHeight goes, minHeight is the XML attribute name you can use in a layout file. setMinimumHeight is the corresponding View API method to do the same thing.
Just calling
btn.setMinHeight(0);
or
btn.setMinimumHeight(0);
didn't work for me.
It worked when I called both methods, like that:
btn.setMinHeight(0);
btn.setMinimumHeight(0);
Checked and rechecked, it's definitely the case, as weird as it looks.
Button was created programmatically, no XML, but it was a part of a custom numeric control that does have an XML description.
EDIT:
setMinHeight is defined by TextView, while setMinimumHeight is defined by View. According to the docs, the greater of the two values is used, so both must be set. minHeight attribute in XML corresponds to the setMinimumHeight method. Thanks to@David Liu for this clarification.
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