如何在RN中的视图末尾放置2个文本组件?

问题描述 投票:0回答:1

我想实现这个结果

enter image description here

但这是当前行为

enter image description here

您可能会注意到两个Text组件均未正确对齐。

这是代码

<View style={{ flexDirection: 'row', marginRight: 7, borderWidth: 2 }}>
     <Text style={{ color: '#0022FF', fontWeight: 'bold', fontSize: 20, alignSelf: 'flex-end', marginRight: 5 }}>2.6</Text>
     <Text style={{ color: '#0022FF', fontSize: 9, alignSelf: 'flex-end' }}>Bar</Text>
</View>

你们能帮我吗?

react-native react-native-android react-native-ios react-native-component
1个回答
0
投票

我认为,如果将两个文本都包装在另一个<Text>组件中,则这样应该可以工作:

<View style={{ flexDirection: 'row', marginRight: 7, borderWidth: 2 }}>
  <Text>
     <Text style={{ color: '#0022FF', fontWeight: 'bold', fontSize: 20, alignSelf: 'flex-end', marginRight: 5 }}>2.6</Text>
     <Text style={{ color: '#0022FF', fontSize: 9, alignSelf: 'flex-end' }}>Bar</Text>
  </Text>
</View>
© www.soinside.com 2019 - 2024. All rights reserved.