React-Native 基础五 Height and Width

参考文档:http://facebook.github.io/react-native/docs/height-and-width.html

1. Fixed Dimension 静态尺寸
React-Native所有尺寸都是无单位,密度无关像素

import React,{ Component } from 'react';
import { AppRegistry,View } from 'react-native';

class FixedDimensionsBasics extends Component {
  render() {
    return (
      <View>
        <View style={{width: 50,height: 50,backgroundColor: 'powderblue'}} />
        <View style={{width: 100,height: 100,backgroundColor: 'skyblue'}} />
        <View style={{width: 150,height: 150,backgroundColor: 'steelblue'}} />
      </View>
    );
  }
};

AppRegistry.registerComponent('AwesomeProject',() => FixedDimensionsBasics);

2. Flex Dimension 动态尺寸

import React,View } from 'react-native';

class FlexDimensionsBasics extends Component {
  render() {
    return (
      // Try removing the `flex: 1` on the parent View.
      // The parent will not have dimensions,so the children can't expand.
      // What if you add `height: 300` instead of `flex: 1`?
      <View style={{flex: 1}}>
        <View style={{flex: 1,backgroundColor: 'powderblue'}} />
        <View style={{flex: 2,backgroundColor: 'skyblue'}} />
        <View style={{flex: 3,() => FlexDimensionsBasics);

flex类似于Android的weight,不作过多解释

相关文章

react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...
react 本身提供了克隆组件的方法,但是平时开发中可能很少使...
mobx 是一个简单可扩展的状态管理库,中文官网链接。小编在接...
我们在平常的开发中不可避免的会有很多列表渲染逻辑,在 pc ...