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

时间:2020-02-18 13:37:03

标签: react-native react-native-android react-native-ios react-native-component

我想达到这个结果

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>

你们可以帮我吗?

1 个答案:

答案 0 :(得分:1)

我认为,如果您将两个文本都包装在另一个<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>