Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : overriding Button minheight programmatically

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 !

like image 279
Dan Chaltiel Avatar asked Dec 01 '22 18:12

Dan Chaltiel


2 Answers

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.

like image 37
Michael Krause Avatar answered Dec 03 '22 07:12

Michael Krause


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.

like image 147
Flot2011 Avatar answered Dec 03 '22 06:12

Flot2011