在android开发过程中,对于控件的高度,宽度,虽然在xml中用android:layout_height="match_parent"设置了 高度(match_parent和fill_parent是一样的,2.2版本后就用match_parent代替fill_parent了。)但有时, 程序需要,必须在代码里,动态设置控制的高度或宽度。

我想当然的用setHeight(100);设置了高度,以为这样就可以了,但偏偏没有生效,google了好久都没结果,急得要命。后来在一篇文章找到了答案。

当设置的高度比原来默认的高度要小时,调用setHeight();是不生效的,这时要这样设置:

1
2
3
editText=(EditText)findViewById(R.id.myEditText);
// editText.setHeight(10); //不生效
editText.getLayoutParams().height = 100;//这样设置生效。

相关文章:

  • 2021-11-03
  • 2022-01-15
  • 2021-08-17
  • 2021-11-28
  • 2022-01-04
  • 2021-12-04
  • 2021-12-05
  • 2021-10-31
猜你喜欢
  • 2022-12-23
  • 2021-05-13
  • 2021-08-08
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-05-09
相关资源
相似解决方案