帧布局可以把他看成可以层叠的布局,即每一个子布局都会依次层叠,且不设置属性的情况下,都从左上角开始布局。
示例:
local layout =
{
FrameLayout;
layout_width = "fill",
layout_height = "fill",
{
LinearLayout,
layout_width = "300dp",
layout_height = "300dp",
backgroundColor = 0xffff5553
},
{
LinearLayout,
layout_width = "200dp",
layout_height = "200dp",
backgroundColor = 0xffffb53b
},
{
LinearLayout,
layout_width = "100dp",
layout_height = "100dp",
backgroundColor = 0xff00c443
},
}
activity.setContentView(loadlayout(layout))
位置控制
当你想让你的子布局呈规律性排布的话,就需要用到layout_gravity属性,此属性是在子布局定义的。
常用如下取值:
- top :将对象放在其容器的顶部,不改变其大小
- bottom:将对象放在其容器的底部,不改变其大小
- left:将对象放在其容器的左侧,不改变其大小
- right:将对象放在其容器的右侧,不改变其大小
- center_vertical:将对象纵向居中,不改变其大小
- fill_vertical:必要的时候增加对象的纵向大小,以完全充满其容器
- center_horizontal:将对象横向居中,不改变其大小
- fill_horizontal:必要的时候增加对象的横向大小,以完全充满其容器
- center:水平方向填充
- fill:必要的时候增加对象的横纵向大小,以完全充满其容器