//1.设置模式
'use strict';
//2.导入库
var React = require('react-native');
//3.定义变量添加依赖项
var {
AppRegistry,
StyleSheet,
View,
} = React;
//4.创建组件类
var HelloReact = React.createClass({
//组件的渲染方法
//设置视图 View
render: function() {
return (
<View style = {{backgroundColor: 'gray', width: 300, height:300, }}>
<View style = {{backgroundColor: 'yellow', width: 50, height: 50}}/>
</View>
);
}
});
//5.注册
AppRegistry.registerComponent('HelloReact', () => HelloReact); var HelloReact = React.createClass({ //创建组件类
//组件的渲染方法
//设置视图 View
render: function() {
return (
<View style = {{backgroundColor: 'gray',
width: 300, height:300,
marginHorizontal: 50,
paddingLeft: 20,
paddingTop: 50,
flexDirection: 'row',
}}>
<View style = {{backgroundColor: 'blue', width: 50, height: 50}}/>
</View>
);
}
});<View style = {{backgroundColor: 'gray',
width: 300, height:300,
top: 20,
flexDirection: 'row', //按行
justifyContent: 'flex-end', //子视图从结束位置对齐(按行时,则从右边对齐;按列时,则从底部开始对齐)
}}>
<View style = {{backgroundColor: 'blue', width: 50, height: 50}}/>
<View style = {{backgroundColor: 'yellow', width: 50, height: 50}}/>
<View style = {{backgroundColor: 'green', width: 50, height: 50}}/>
</View> <View style = {{backgroundColor: 'gray',
width: 300, height:300,
top: 20,
flexDirection: 'column', //按列
alignItems: 'stretch', //子视图被拉伸
}}>
<View style = {{backgroundColor: 'blue', height: 50}}/>
<View style = {{backgroundColor: 'yellow', width: 50, height: 50}}/>
<View style = {{backgroundColor: 'green', width: 50, height: 50}}/>
</View> <View style = {{backgroundColor: 'gray',
width: 300, height:300,
top: 20,
flexDirection: 'row', //按列
alignItems:'stretch', //子视图被拉伸
}}>
<View style = {{backgroundColor: 'blue', width: 50, }}/>
<View style = {{backgroundColor: 'yellow', width: 50, height: 50}}/>
<View style = {{backgroundColor: 'green', width: 50, height: 50}}/>
</View>【Facebook的UI开发框架React入门之七】多View布局与样式Style简介(iOS平台)-goodmao
原文:http://blog.csdn.net/maoyingyong/article/details/46563971