我想创建一个类似于iMessage的布局的消息传递视图,其中聊天“泡沫”是其内容的大小,直到它获取是一定的宽度。像这样: Nativescript:使标签跨度宽度的内容,然后包装在最大宽度
有了nativescript,我无法找到一个适合这个的布局。我尝试过使用GridLayout,但列的自动属性似乎意味着它将是内容的大小,即使内容的大小超出了视图范围。
<GridLayout width="100%" columns="40, auto" rows="auto, 20" class="msg them" visibility="{{is_me ? 'collapsed' : 'visible'}}">
<Image class="authorimg" col="0" stretch="aspectFill" verticalAlignment="top" src="{{user.profile_photo ? user.profile_photo.sizes.tiny_square : ''}}" />
<StackLayout class="msg_text" col="1">
<Label text="{{message}}" textWrap="true" verticalAlignment="top" />
</StackLayout>
<Label class="msg_timestamp" text="{{author}}" verticalAlignment="top" row="1" colSpan="2" />
</GridLayout>
产生这样的:
通知的较长的不换,尽管textWrap =真上的标签。
硬币的另一面是这样的:
<GridLayout width="100%" columns="40, *" rows="auto, 20" class="msg them" visibility="{{is_me ? 'collapsed' : 'visible'}}">
<Image class="authorimg" col="0" stretch="aspectFill" verticalAlignment="top" src="{{user.profile_photo ? user.profile_photo.sizes.tiny_square : ''}}" />
<StackLayout class="msg_text" col="1">
<Label text="{{message}}" textWrap="true" verticalAlignment="top" />
</StackLayout>
<Label class="msg_timestamp" text="{{author}}" verticalAlignment="top" row="1" colSpan="2" />
</GridLayout>
唯一的区别是在GridLayout的列,在这种情况下其设置为*(使用可用区域的其余部分)。也就是说然而,产生这样的:
注意,短消息跨越整个宽度。我想在标签上我需要类似width =“auto”的东西。我无法弄清楚这样一种布局,它可以适应两种实现方式中最好的一种,小文本的小气泡和长文本的气泡。
嘿,你有没有尝试在你的gridLayout中创建另一列? Something like columns =“40,*,*” – Kansen
@Kansen我确实尝试过!对第二列(带有消息标签的列)使用*会使Label跨越列的整个宽度。然后在那里添加另一个只是分隔这两列之间的剩余空间,产生这个:https://d3vv6lp55qjaqc.cloudfront.net/items/2E1S2k0C3S2t1s233T3j/Screenshot%202016-08-31%2008.42.59.png?X-CloudApp- Visitor-Id = 196928 – davecoffin