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

1,284 阅读1分钟

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

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

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

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

需要再嵌套一个布局


运行一下 :

.

那么问题来了:

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

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