1:Stack组件默认所有的子组件都是叠加的,可以根据Alignment属性来控制相对位置的定位显示
return Center(
child: Stack(//stack 中所有的组件 相对于 Center组件进行相对位子操作
// alignment: Alignment.bottomLeft, //子组件的 偏移,操控children中的所有元素
alignment:Alignment(1, 1),//范伟-1--1, 类事于iOS中 CALayer 绘制时候位置猫点
children: [
Container(
width: 200,
height: 200,
decoration: BoxDecoration(
color: Colors.red,
),
),
Text('我是一个文本'),
],
),
);
2:除了Alignment属性来修饰定位外,还可以使用Align组件进行单个组件定位
child: Stack(
children: [
Container(
width: 200,
height: 200,
decoration: BoxDecoration(
color: Colors.red,
),
),
Align(//使用Align组件包裹 Text,然后可以用属性alignment进行单个定位
alignment: Alignment.bottomCenter,
child: Text('我是一个文本'),
)
],
),
3:除了Align组件可以进行单个子空间定位之外,还可以使用Positioned组件单个定位,和Align区别在于Positioned组件可以进行绝对定位:
Positioned(
bottom: 200,
left: 200,
child: Text('我是一个文本'),
),
Positioned属性中botton、left、right、top 可以直接传入int 进行绝对定位