React Native-3.React Native中的主要布局属性介绍和练习
我们搞出些事情
React Native 中的主要flexbox属性介绍
Just Do it1、alignItems该属性的用法和欠扁的align-items,区别在于写法使用驼峰拼写法,语法:
2、alignSelf该属性的用法同赏遍的
3、flex该属性的用法同上一章节的flex,语法:
4、flexDirection该属性的用法同上面的
5、flexWrap该属性的用法同上面的
6、justifyContent该属性的用法同上边的
光说不练假把式我们来用学习CSS的经典模型:盒子模型,来联系我们学习的属性 实现效果: 代码: 'use strict';
var React = require('react-native');
var {
AppRegistry,StyleSheet,Text,View,} = React;
var wxsPrj = React.createClass({
render: function() {
return (
<View style = {styles.boxRect}>
<View style = {styles.top}>
<Text style = {styles.myTextColor}>
top
</Text>
</View>
<View style = {styles.centerView}>
<View style = {[styles.left,styles.height100,styles.width50]}>
<Text style = {styles.myTextColor}>
left
</Text>
</View>
<View style = {[styles.right,styles.width50]}>
<Text style={styles.myTextColor}>
right
</Text>
</View>
</View>
<View style = {styles.bottom}>
<Text style = {styles.myTextColor}>
bottom
</Text>
</View>
</View>
);
}
});
var styles = StyleSheet.create({
myTextColor: {
height:20,width:50,alignSelf:'center',textAlign:'center',color: '#ffffff',},boxRect: {
backgroundColor: '#555555',flexDirection:'column',flexWrap:'nowrap',justifyContent:'flex-start',width:200,height:200,top: {
backgroundColor: '#666666',justifyContent: 'center',flexDirection:'row',height:50,bottom: {
backgroundColor: '#666666',right: {
backgroundColor: '#666666',left: {
backgroundColor: '#666666',centerView: {
justifyContent:'space-between',height50: {
height: 50,width50: {
width: 50,height100:{
height:100,}
});
AppRegistry.registerComponent('wxsPrj',() => wxsPrj);
运行后的效果: 最后总是得说点什么装一下。。。总结一下CSS中标签的书写格式和React Native中标签的书写格式的区别: - CSS以分号(;)结尾 ,RN 以逗号(,)结尾; - CSS中key,value都不加引号,RN中属于JavaScript对象 ,如果value为字符串,需要用引号引起来,并且key值中间不能出现“-“,一定要转为驼峰命名方式。 - CSS中,value值为数字时,需要带单位,RN中则不用带。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |