简体   繁体   English

Flutter 通过文本小部件显示文本时,有时文本显示为两行

[英]Flutter when displaying text via the text widget, sometimes the text is displayed into two lines

i'am trying to display a text using a text widget in flutter, but i'am having an issue with the final result the text breaks into two line event somme space is available... thank for your help... you can find a screenshot from my emulator我正在尝试使用 flutter 中的文本小部件显示文本,但我对最终结果有疑问,文本分成两行事件 somme space 可用...感谢您的帮助...您可以找到我的模拟器的截图

You can specify the maximum number of lines on a text widget by passing the maxLines parameter.您可以通过传递maxLines参数来指定文本小部件上的最大行数。

Text(_someLongText, maxLines: 1);

which of course means the text will cut off before it goes to a next line:这当然意味着文本将在进入下一行之前被切断:

without maxlines:没有最大线:

+-------------+
| some text   |
| long text   |
+-------------+

with maxlines: 1最大线:1

+-------------+
| some text lo|
+-------------+

You can define the behaviour of the overflow text with the overflow parameter:您可以使用溢出参数定义溢出文本的行为:

Column(children: [
  Text('this si some long text', maxLines: 1, overflow: TextOverflow.clip),
  Text('this si some long text', maxLines: 1, overflow: TextOverflow.elipsis),
  Text('this si some long text', maxLines: 1, overflow: TextOverflow.fade),
  Text('this si some long text', maxLines: 1, overflow: TextOverflow.visible),
]);

will make:将使:

+-------------+
| this is some|
+-------------+
+-------------+
| this is s...|
+-------------+
+-------------+
| this is some| // can't do this one but the text fades away
+-------------+
+-------------+
| this is some long text
+-------------+

Hopefully you can fix the issue with that.希望你能解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM