[英]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. 搜索如何减少按钮内的填充,我在https://stackoverflow.com/a/20323723/3888000中发现我应该将我的按钮的最小高度设置为xml文件中的0dp。 And yes, it works for me. 是的,它对我有用。
Problem is : I want to create my button programmatically, and neither setMinimumHeight(1) nor setMinHeight(1) did work. 问题是:我想以编程方式创建我的按钮,setMinimumHeight(1)和setMinHeight(1)都不起作用。 How to do it ? 怎么做 ?
By the way, what is the difference between these two methods ? 顺便问一下,这两种方法有什么区别?
Thank you ! 谢谢 !
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. Button是以编程方式创建的,没有XML,但它是具有XML描述的自定义数字控件的一部分。
EDIT: 编辑:
setMinHeight is defined by TextView, while setMinimumHeight is defined by View. setMinHeight由TextView定义,而setMinimumHeight由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. XML中的minHeight属性对应于setMinimumHeight方法。 Thanks to@David Liu for this clarification. 感谢@ David Liu的澄清。
I think you should try using setPadding(0,0,0,0); 我想你应该尝试使用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. 就minHeight和minimumHeight而言,minHeight是您可以在布局文件中使用的XML属性名称。 setMinimumHeight is the corresponding View API method to do the same thing. setMinimumHeight是相应的View API方法,可以做同样的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.