Layout 使用“对齐”或“定位颤振”有什么区别
她是一个使用定位小部件和对齐小部件的具体例子! 但我不知道该用什么!虽然最初的问题是设置一些晶圆厂相对于其容器的偏移量,而不是屏幕的偏移量Layout 使用“对齐”或“定位颤振”有什么区别,layout,dart,flutter,alignment,Layout,Dart,Flutter,Alignment,她是一个使用定位小部件和对齐小部件的具体例子! 但我不知道该用什么!虽然最初的问题是设置一些晶圆厂相对于其容器的偏移量,而不是屏幕的偏移量 Stack( children: <Widget>[ Positioned(left: 0.0, child: Text("Top\nleft")), Positioned(bottom: 0.0, child: Text("Bottom\nleft")), Positioned(top
Stack(
children: <Widget>[
Positioned(left: 0.0, child: Text("Top\nleft")),
Positioned(bottom: 0.0, child: Text("Bottom\nleft")),
Positioned(top: 0.0, right: 0.0, child: Text("Top\nright")),
Positioned(bottom: 0.0, right: 0.0, child: Text("Bottom\nright")),
Positioned(bottom: 0.0, right: 0.0, child: Text("Bottom\nright")),
Positioned(left: width / 2, top: height / 2, child: Text("Center")),
Positioned(top: height / 2, child: Text("Center\nleft")),
Positioned(top: height / 2, right: 0.0, child: Text("Center\nright")),
Positioned(left: width / 2, child: Text("Center\ntop")),
Positioned(left: width / 2, bottom: 0.0, child: Text("Center\nbottom")),
],
)
Example #2 (Using Align in Stack)
Stack(
children: <Widget>[
Align(alignment: Alignment.center, child: Text("Center"),),
Align(alignment: Alignment.topRight, child: Text("Top\nRight"),),
Align(alignment: Alignment.centerRight, child: Text("Center\nRight"),),
Align(alignment: Alignment.bottomRight, child: Text("Bottom\nRight"),),
Align(alignment: Alignment.topLeft, child: Text("Top\nLeft"),),
Align(alignment: Alignment.centerLeft, child: Text("Center\nLeft"),),
Align(alignment: Alignment.bottomLeft, child: Text("Bottom\nLeft"),),
Align(alignment: Alignment.topCenter, child: Text("Top\nCenter"),),
Align(alignment: Alignment.bottomCenter, child: Text("Bottom\nCenter"),),
Align(alignment: Alignment(0.0, 0.5), child: Text("Custom\nPostition", style: TextStyle(color: Colors.red, fontSize: 20.0, fontWeight: FontWeight.w800),),),
],
);
> Blockquot
堆栈(
儿童:[
定位(左:0.0,子:文本(“上\n左”),
已定位(底部:0.0,子级:文本(“底部\n左侧”),
已定位(顶部:0.0,右侧:0.0,子级:文本(“顶部\n右侧”),
已定位(底部:0.0,右侧:0.0,子级:文本(“底部\n右侧”),
已定位(底部:0.0,右侧:0.0,子级:文本(“底部\n右侧”),
定位(左:宽度/2,顶部:高度/2,子项:文本(“中心”),
已定位(顶部:高度/2,子级:文本(“中间\n左侧”),
已定位(顶部:高度/2,右侧:0.0,子级:文本(“中间\n右侧”),
定位(左:宽度/2,子项:文本(“中心\n顶部”),
已定位(左:宽度/2,底部:0.0,子项:文本(“中间\n底部”)),
],
)
示例2(使用堆栈中的对齐)
堆叠(
儿童:[
对齐(对齐方式:alignment.center,子项:文本(“中心”),),
对齐(对齐方式:alignment.topRight,子项:文本(“顶部\n右侧”),),
对齐(对齐方式:alignment.centerRight,子项:文本(“居中\n右侧”),),
对齐(对齐方式:alignment.bottomRight,子项:文本(“Bottom\nRight”),),
对齐(对齐方式:alignment.topLeft,子项:Text(“Top\nLeft”),),
对齐(对齐方式:alignment.centerLeft,子项:文本(“居中\nLeft”),),
对齐(对齐方式:alignment.bottomLeft,子项:文本(“Bottom\nLeft”),),
对齐(对齐方式:alignment.topCenter,子项:文本(“顶部\nCenter”),),
对齐(对齐方式:alignment.bottomCenter,子项:文本(“底部\n中心”),),
对齐(对齐:对齐(0.0,0.5),子项:文本(“自定义\n拼接”,样式:TextStyle(颜色:Colors.red,fontSize:20.0,fontWeight:fontWeight.w800),,),
],
);
>Blockquot
e
定位
只能在堆栈
中使用,并相对于堆栈
大小定位子级
Align
将在其父对象中尽可能大(或者如果传递了heightFactor
,widthFactor
,则为相对于子对象的大小),并将其子对象相对于自身定位Align
可以在任何地方使用,而不仅仅是在堆栈中使用
Positioned
是一种基于偏移的对齐方式,使用DP作为单位
Align
使用父级大小的%
因此,对齐(0.1,0.1)
不能使用定位的表示。类似地,Align
不能表示定位的(顶部:10,左侧:10)
其次,定位
位于不同的流上
Stack
可以根据其子项的大小调整自身大小不包括定位的小部件
因此,使用Align
vsPositioned
会导致堆栈采用不同的大小