ReactNative / Flex:如何将两个组件水平排列?

时间:2016-05-27 21:06:12

标签: reactjs react-native react-jsx jsx

如何使用flex?在同一行中将2个Image-Components排列在另一个旁边?

像这样:

|| (图1)|| (图2)||

3 个答案:

答案 0 :(得分:4)

flexDirection: 'row'是你的朋友

答案 1 :(得分:1)

我觉得这样......

<View style={{flexDirection:'row', alignItems:'center', justifyContent:'center'}}>
  <Image source... />
  <Image source... />
</View>

现在,根据您希望水平间隔的方式,您可以使用不同的justifyContent

答案 2 :(得分:0)

首先我们将flex方向设置为row,这将水平排列子项。为了使组件水平居中,我们使用alignItems属性,然后使用justifyContent垂直居中组件。 试试这样:

&#13;
&#13;
var styles = StyleSheet.create({
    firstComponent:{
        flexDirection:'row'    
    },
    childrens:{     
        width: 120,       
        color:'#fff',
        alignItems:'center'
    }
});
&#13;
&#13;
&#13;