如何在 Flutter 中垂直和水平居中文本? [英] How do I center text vertically and horizontally in Flutter?

查看:87
本文介绍了如何在 Flutter 中垂直和水平居中文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在 Flutter 中垂直和水平居中放置 Text 小部件的内容.我只知道如何使用 Center(child: Text("test")) 而不是内容本身来居中小部件本身.默认情况下,它向左对齐.在 Android 中,我相信实现这一点的 TextView 的属性称为 gravity.

I'd like to know how to center the contents of a Text widget vertically and horizontally in Flutter. I only know how to center the widget itself using Center(child: Text("test")) but not the content itself. By default, it's aligned to the left. In Android, I believe the property of a TextView that achieves this is called gravity.

我想要的例子:

推荐答案

文本对齐居中属性设置仅水平对齐.

Text alignment center property setting only horizontal alignment.

我使用下面的代码将文本垂直和水平居中.

I used below code to set text vertically and horizontally center.

代码:

      child: Center(
        child: Text(
          "Hello World",
          textAlign: TextAlign.center,
        ),
      ),

这篇关于如何在 Flutter 中垂直和水平居中文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆