【问题标题】:Limit wrapped Text to actual text将包装文本限制为实际文本
【发布时间】:2022-09-27 14:45:21
【问题描述】:

我有一个由三个相等部分组成的行。代码如下,并附上输出(截图)

Row(
    children:[
      Spacer(),
      Expanded(child: Container(color:Colors.orange, child: Text(\"The quick brown fox jumps over the lazy dog\", style: TextStyle(fontSize: 24),))),
      Spacer()
    ]
  ),

我想在橙色框中水平居中文本(同时保持两条线彼此对齐)。因此,如果有意义的话,我想将“dog”之后的一半空间向左移动,在“The”和“jumps”之前。

我怎样才能做到这一点?我玩过 IntrinsicWidth、Center、Row、textAlign 但似乎没有任何效果

  • 您是否尝试过中心小部件
  • 或对齐小部件
  • 尝试了 Center 和 Align 但他们似乎都没有在这里做的伎俩

标签: flutter flutter-layout


【解决方案1】:

在您的文本小部件中添加textAlign: TextAlign.center

用这个:

 Row(
children:[
  Spacer(),
  Expanded(child: Container(color:Colors.orange, child: Text("The quick brown fox jumps over the lazy dog", style: TextStyle(fontSize: 24,),textAlign: TextAlign.center,))),
  Spacer()
]

),

【讨论】:

    【解决方案2】:

    试试下面的代码:

    Row(
        children:[
          Spacer(),
          Expanded(
            child: Container(
            color: Colors.orange,
            child: Text(
              "The quick brown fox jumps over the lazy dog",
              textAlign: TextAlign.center,
              style: TextStyle(fontSize: 24),
            ),
          ),
        ),
        Spacer()
      ]
    ),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-29
      • 2012-07-18
      • 2016-09-18
      • 2014-12-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多