flutter里如何使组件居于屏幕中间
有多种方式可以使组件居于屏幕中间,以下是其中的几种:
- 使用 Center 组件将子组件居中。
Center(
child: YourWidget(),
)
- 使用 Align 组件指定子组件的对齐方式,将其居中。
Align(
alignment: Alignment.center,
child: YourWidget(),
)
- 使用 Column 或 Row 组件将子组件居中。
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
YourWidget(),
],
)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
YourWidget(),
],
)
- 使用 SizedBox 组件指定子组件的宽高,将其居中。
SizedBox(
width: double.infinity,
height: double.infinity,
child: Center(
child: YourWidget(),
),
)
- 使用 Stack 和 Positioned 组件将子组件居中。
Stack(
children: <Widget>[
Positioned(
left: 0,
top: 0,
right: 0,
bottom: 0,
child: YourWidget(),
),
],
)
以上是几种常见的将组件居于屏幕中间的方式,具体使用哪种方式要根据实际情况来决定。
原文地址: https://www.cveoy.top/t/topic/bS3q 著作权归作者所有。请勿转载和采集!