Flutter 文字对齐:左对齐、居中对齐、右对齐
Flutter 对字体的左右对齐可以通过'TextAlign' 属性来实现。'TextAlign' 属性有三个值:'left'、'center' 和 'right',分别表示左对齐、居中对齐和右对齐。
例如:
Text(
'Hello World',
textAlign: TextAlign.center,
);
上面的代码将文本居中对齐。
如果想要实现文本左右对齐,可以使用'Row' 组件。将文本放在'Row' 组件中,然后使用'MainAxisAlignment' 属性来控制文本的位置。
例如:
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Left'),
Text('Right'),
],
);
上面的代码将两个文本左右对齐。'MainAxisAlignment.spaceBetween' 属性会让两个文本之间有空隙,让它们分别靠左和靠右对齐。
原文地址: https://www.cveoy.top/t/topic/mYDx 著作权归作者所有。请勿转载和采集!