Layout_width,Layout_height这两个参数设置View在布局中的长宽的,这个View必须存在于一个父布局中,这两个参数才会有效。

比如我们设置页面布局只有一个button

踩坑日记-Layout_width,Layout_height不起作用

发现我们我设置的layout_height,layout_width没有作用

踩坑日记-Layout_width,Layout_height不起作用

所以 如果页面的xml布局中只有这一个View的话,它的Layout_width,Layout_height参数是不起作用的。

需要再嵌套一个布局

踩坑日记-Layout_width,Layout_height不起作用
运行一下 :

踩坑日记-Layout_width,Layout_height不起作用.

那么问题来了:

按这样说那最外层的RelativeLayout的Layout_width,Layout_height不也应该不起作用了吗?

不,在setContentView()方法中,Android会自动为当前页面再嵌套一个FrameLayout.使这个页面的布局Layout_width,Layout_height生效

踩坑日记-Layout_width,Layout_height不起作用

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-26
  • 2021-05-29
  • 2022-02-03
  • 2021-07-27
猜你喜欢
  • 2021-07-19
  • 2021-10-11
  • 2021-10-11
  • 2021-10-25
  • 2021-07-23
  • 2021-10-13
  • 2022-01-14
相关资源
相似解决方案