RN盒模型以及FlexDirection布局

  • 颜色值
https://reactnative.cn/docs/0.51/colors.html#content
  • 盒模型
  • 加边框

FlexDirection基本布局

  • 垂直关系

这里写图片描述

  • 是否换行

这里写图片描述

  • 主轴排列方式

这里写图片描述

  • 次轴排列方式

这里写图片描述

  • 学会使用界面调试器进行调试

这里写图片描述

这里写图片描述

  • 三个Item平分布局

  • Item组件

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  Image,
  Dimensions,
} from 'react-native';

const {width, height} = Dimensions.get('window');

const imageWidth = width / 3 - 10 * 2;
const imageHeight = imageWidth / 0.7;

type Props = {};
export default class Item extends Component<Props> {
  render() {
    return (
      <View style={styles.container}>
        <Image 
        source={require('./src/img/poster.jpg')} 
        style={styles.image}
        />
        <Text style={styles.text}>
        金刚狼·殊死一战
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    width:imageWidth,
    flexDirection:'column'
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  text:{
    marginTop:5,
    width:imageWidth,
    fontSize:20,
    fontWeight:'bold',
    textAlign:'center'
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
  image:{
    width:imageWidth,
    height:imageHeight,
  },
});
  • 主组件
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  Image,
} from 'react-native';

import Item from './Item';

type Props = {};
export default class App extends Component<Props> {
  render() {
    return (
      <View style={styles.container}>
        <Item/>
        <Item/>
        <Item/>
      </View>
    );
  }
}

const styles = StyleSheet.create({  
  container:{
    flexDirection:'row',
    justifyContent:'space-between',
    paddingHorizontal:15,
  },
});
  • 效果图
    这里写图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值