【问题标题】:How to center Text and make as big as given size如何使文本居中并与给定大小一样大?
【发布时间】:2022-07-26 20:51:36
【问题描述】:

我有一个视图,其中有 GestureDetector,它具有 onHorizo​​ntalDragEnd 功能。 作为一个孩子,我希望文本居中,并且可以从屏幕上的每个位置开始水平滑动。 我的问题是,当我将 Text 放在 Center 小部件中时,我只能在 Text 上开始滑动。

我试图用容器包装文本。它修复了滑动问题,但文本没有居中。

这是现在的样子:

Center(
   child: Container(
   height: size.height * 0.6,
   child: Text(
       'example text',
       textAlign: TextAlign.center,
       ),
   ),
)

【问题讨论】:

    标签: flutter dart layout flutter-layout


    【解决方案1】:

    在你的容器中添加alignment: Alignment.center

    Center(
       child: Container(
       height: size.height * 0.6,
       alignment: Alignment.center, //HERE
       child: Text(
           'example text',
           textAlign: TextAlign.center,
           ),
       ),
    )
    

    【讨论】:

      【解决方案2】:
      Center(
        child: Container(
          height: size.height * 0.6,
          child: Center(
            child: Text(
              'example text',
              textAlign: TextAlign.center,
            ),
          ),
        ),
      )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-06
        • 1970-01-01
        • 1970-01-01
        • 2017-09-09
        • 1970-01-01
        • 2014-01-16
        相关资源
        最近更新 更多