react-native 布局篇之position

position布局

position:enum('absolute','relative')。先简单的看一下示例图

react-native 布局篇之position_第1张图片
Snip20160627_1.png
  • position:'relative'
    相对布局。这个和html的position有很大的不同,他的相对布局不是相对于父容器,而是相对于兄弟节点。
  • position:'absolute'
    绝对布局。这个是相对于父容器进行据对布局。绝对布局是脱离文档流的,不过奇怪的是依旧在文档层次结构里面,这个和html的position也很大不一样。另外还有一个和html不一样的是,html中position:absolute要求父容器的position必须是absolute或者relative,如果第一层父容器position不是absolute或者relative,在html会依次向上递归查询直到找到为止,然后居于找到的父容器绝对定位。
  • position 示例代码
/**
 * Created by GXZ on 16/6/27.
 */
import React,{Component} from 'react';
import {
    Text,
    View,
    ScrollView
} from 'react-native';

export default class PositionExample extends Component {
    constructor(props) {
        super(props);
        this.state = {};
    }

    render() {
        return (
            
                
                    FlexBox布局
                    
                        
                        
                        
                    
                    position=relative,top:20
                    
                        
                        
                        
                    
                    position=absolute,top:20
                    
                        
                        
                        
                    
                
            
        );
    }
}

const styles = {
    container: {
        height: 180,
        backgroundColor: '#CCCCCC',
        marginBottom: 10,
    },
    box1: {
        width: 50,
        height: 50,
        backgroundColor: '#FF0000'
    },
    box2: {
        width: 50,
        height: 50,
        backgroundColor: '#00FF00'
    },
    box3: {
        width: 50,
        height: 50,
        backgroundColor: '#0000FF'
    }
};

你可能感兴趣的:(react-native 布局篇之position)