如何将多个NativeScript变量显示为句子

时间:2017-04-21 11:31:05

标签: nativescript angular2-nativescript

我在将多个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

我想要你好吗?你好吗?你好吗?&#39;转到第一行并测试&#39;从&#39;按钮&#39;开始。 ?

喜欢这个

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>

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

编辑:

我缩小了问题:两条长字符串无法在同一行开始。

1 个答案:

答案 0 :(得分:0)

FlexBoxLayout有办法包装。

还有另一个名为WrapLayout的布局。

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