Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native React Native:如何对齐内联文本?_React Native_Flexbox - Fatal编程技术网

React native React Native:如何对齐内联文本?

React native React Native:如何对齐内联文本?,react-native,flexbox,React Native,Flexbox,我想这样做,两个文本都在一条水平线上,其中一个在中间,另一个在右边: 这就是我拥有的,忽略颜色(根本不起作用): 风格: rowLabelText: { color: "#0B1219", fontFamily: Fonts.Knockout31JuniorMiddleWeight, fontSize: 16.0, }, 标记: <View style={{flexDirection: 'row', height: 30, flexWrap: '

我想这样做,两个文本都在一条水平线上,其中一个在中间,另一个在右边:

这就是我拥有的,忽略颜色(根本不起作用):

风格:

  rowLabelText: {
    color: "#0B1219",
    fontFamily: Fonts.Knockout31JuniorMiddleWeight,
    fontSize: 16.0,
  },
标记:

    <View style={{flexDirection: 'row', height: 30, flexWrap: 'wrap', backgroundColor: 'green'}}>
      <View style={{ flex: 1, backgroundColor: 'red', justifyContent: 'center', alignSelf: 'center'}}>
        <Text style={styles.rowLabelText}>
          adjkfdasjkfaskj
        </Text>
      </View>
      <View style={{ flex: 1, backgroundColor: 'blue', justifyContent: 'center', alignSelf: 'flex-end' }}>
        <Text style={styles.rowLabelText}>
          adjkfdasjkfaskj
        </Text>
      </View>
    </View>

adjkfdasjkfaskj
adjkfdasjkfaskj


我有麻烦了。有人能帮我吗?

一种方法是在屏幕的整个宽度上居中文本,同时在居中文本的右侧有一些文本,即在右侧文本上使用绝对定位

通过在右侧文本上使用绝对定位,它不会影响居中文本的位置

<View style={{flexDirection: 'row'}}>
    <View style={{flex:1, alignItems: 'center', backgroundColor: 'red'}}>
        <Text>50%</Text>
    </View>
    <View style={{position:'absolute', right: 20, backgroundColor: 'blue'}}>
        <Text>+$0.80</Text>
    </View>
</View>

50%
+$0.80

看来您的问题在于
alignSelf
您想使用
alignItems

这就是您的代码的外观

你的看法:

<View style={styles.textContainer}>

     <View style={styles.leftContainer}>
        <Text style={styles.rowLabelText}>
          adjkfdasjkfaskj
        </Text>
     </View>

     <View style={styles.rightContainer}>
        <Text style={styles.rowLabelText}>
          adjkfdasjkfaskj
        </Text>
     </View>

</View>
  textContainer:{
    flexDirection: 'row',
    height: 30,
    backgroundColor: 'green'
  },
  leftContainer:{
    flex: 1,
    justifyContent: 'center',
    alignItems:'center',
    backgroundColor: 'red',
  },
  rightContainer:{
    flex: 1,
    justifyContent: 'center',
    alignItems: 'flex-end',
    backgroundColor: 'blue',
  },
  rowLabelText: {
    color: "#0B1219",
    fontSize: 16.0,
  },