【问题标题】:How to display multiple NativeScript variables as sentence如何将多个 NativeScript 变量显示为句子
【发布时间】:2017-04-24 16:39:12
【问题描述】:

我在将多个 NativesScript 变量显示为句子时遇到问题。

我有 5 个变量:

string1 = 'Hello';
string2 = 'John'; 
string3 = 'how are you? how are you? how are you?'; 
string4 = 'Button'; 
string5 = 'Test Test Test Test Test Test Test Test Test Test Test Test 
          Test Test Test Test';   

我正在努力实现:

Hello John how are you? how are you? how are you? Button Test Test Test 
Test Test Test Test Test Test Test Test Test Test Test Test Test

string2 和 string4 应该是可点击的。我用 Span 尝试了 FormattedString,但 span 不能有任何事件,所以它不可点击。我也尝试过 GridLayout ,但它按列或按行分隔(每个变量都从新行开始)。我还尝试了水平方向的 StackLayout,但它没有正确换行并且没有转到另一行。

任何帮助将不胜感激。

已编辑:

在其他一些论坛的帮助下,我的新问题是使用 WrapLayout:

<GridLayout columns="auto,*,auto"  >
 <Label col="0" text="Testing "></Label>
 <WrapLayout col="1">
  <Label text="Hello"  ></Label>
  <Label text="John"></Label>
  <Label text="how are you? how are you? how are you?"></Label>
  <Label text="Button Button Button"></Label>
  <Label text="Test Test Test Test Test Test Test Test Test Test Test 
      Test Test Test Test Test"></Label>
</WrapLayout>
<Label col="2" text="Test2"></Label>

结果:

HelloJohn
how are you? how are you? how are you?
Button Button Button
Test Test Test Test Test Test Test Test 
Test Test Test Test Test Test Test Test

我想问你好吗?你好吗?你好吗?'转到第一行,“测试”与“按钮”在同一行开始?

这样

HelloJohnhow are you? how are you? how are you?
Button Button ButtonTest Test Test Test Test Test Test Test 
Test Test Test Test Test Test Test Test

谢谢

已编辑:

我试过了

<GridLayout columns="auto,*,auto" class="post-top-wrapper">
 <Label col="0" text="Testing "></Label>
 <FlexboxLayout col="1" flexWrap="wrap">
  <Label text="Hello"  ></Label>
  <Label text="John"></Label>
  <Label text="how are you? how are you? how are you?"></Label>
  <Label text="Button Button Button"></Label>
  <Label text="Test Test Test Test Test Test Test Test Test Test Test 
    Test Test Test Test Test"></Label>
</FlexboxLayout>
<Label col="2" text="Test2"></Label>

我得到与上面提到的相同的结果。短字符串没有问题,但是长字符串(不适合一行)不是从同一行开始,而是从新的一行开始。

已编辑:

我已经缩小了问题的范围:两个长字符串不能在同一行开始。

【问题讨论】:

标签: nativescript angular2-nativescript


【解决方案1】:

FlexBoxLayout 有一种包装方式。

还有另一个布局叫做 WrapLayout。

https://docs.nativescript.org/ui/layout-containers#wraplayout

【讨论】:

  • 感谢您的回复。我试过 WrapLayout 和 FlexboxLayout 但每个字符串都换行。 &lt;WrapLayout&gt; &lt;Label text="Hello" &gt;&lt;/Label&gt; &lt;Label text="John"&gt;&lt;/Label&gt; &lt;Label text="how are you? how are you? how are you?"&gt;&lt;/Label&gt; &lt;Label text="Button"&gt;&lt;/Label&gt; &lt;Label text="Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test"&gt;&lt;/Label&gt; &lt;/WrapLayout&gt;
  • 这是关于如何使用 flexbox 的指南。 css-tricks.com/snippets/css/a-guide-to-flexbox 您确实需要在 flexbox 上正确设置子项和父项,以使 wrap 正常工作。
  • @kivid 请检查我更新的问题。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多