简体   繁体   English

按钮的setHeight()和setWidth()

[英]Button's setHeight() and setWidth()

Button's setHeight() and setWidth() API becomes invalid in some situation described below In the official doc , it says about the set API 在下面描述的某些情况下,Button的setHeight()和setWidth()API变得无效。官方文档中 ,它说明了set API

Makes the TextView exactly this many pixels tall. 使TextView恰好有这么多像素高。 You could do the same thing by specifying this number in the LayoutParams. 您可以通过在LayoutParams中指定此数字来执行相同的操作。 Note that setting this value overrides any other (minimum / maximum) number of lines or height setting. 请注意,设置此值将覆盖其他(最小/最大)行数或高度设置。

But in my practice, i found the set API becomes invalid when less than some value. 但是在我的实践中,我发现set API小于某个值时就变得无效。 In another word, it seems to take effect when the value being set is bigger than some default value. 换句话说,当设置的值大于某个默认值时,它似乎生效。

Can somebody explain this to me ? 有人可以向我解释吗?

Every View has it's onMeasure Method you can override. 每个视图都有您可以覆盖的onMeasure方法。 As you can see in Source Code of Android, for a View there is a suggested minimum. 如您在Android的源代码中所看到的,对于View,建议的最低要求是。 Hope it helps :) 希望能帮助到你 :)

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),
getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));
 }

Here you can see full Source Code of View: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.0_r1/android/view/View.java#View.onMeasure%28int%2Cint%29 在这里,您可以查看完整的查看源代码: http : //grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.0_r1/android/view/View.java# View.onMeasure%28int%2Cint 29%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM